learning C# ; first problem with access, and datasets

  • Thread starter Thread starter Jordi Maicas
  • Start date Start date
J

Jordi Maicas

Hi!!

I'm doing a form to make a login, so, user and pass.... and so on.

The problem is that first of all, I check how many records are in the table,
and later I would like to make a do/while. With count it shows always '0'
records, and there's 1 record.

I've got a dataset called usuarios, and with:

int numero;

numero = usuarios.Tables.Count;

Form1 formulario1=new Form1();

formulario1.Show();



IT shows a message like this: The name 'numero' does not exist in the
curent context.



And I don't understand...



Furthermore, in the Form1, I'm doing the same with other table, and it works
fine.
 
Hi,

I don't understand the problem from this description except that in the
given code, you check for the count of tables in the DataSet, not count of
rows in a DataTable, and that you probably try to use 'numero' variable out
of its scope...can you please clarify?
 
Jordi,

Most probably in my idea
numero = usuarios.Tables.Count;
numero = usuarios.Tables[0].Count;

By the way I would not know a construction that would create this as a
Strongly Typed Dataset, while the construction created by you above should
give in normal situations (as you did not build your own collection around a
datatable) give an error.

Cor
 
Ok, I explain the problem.

I've got a form, and I add a dataset. I choose a Typed dataset with the
name: TabStripApp.usuarios. And after that, I add a BindingSource1 and in
DataSource propertie I assign it to DataSource=usuarios1.

The problem now is, how could I know how many records are in the table?

I try with numero=usuarios1.Tables.Count and with
numero=usuarios1.Tables[0].Count and it shows 0, and the table has 1 record.

Another question, sorry I'm a begginer, is about 3 controls:

a. In VS.NET 2008, Tools, Connect to Database. Obviously is for connect to
a database, I think is like a make a connection... where you can choose how
many tables from the database would you like to connect.

If you choose more than one, I think that when you use
usuarios1.Tables[0].Count, or usuarios1.Tables[1].Count you are indicating
these tables, but I think is more easy to use
usuarios1.Tables["products"].Count or usuarios1.Tables["users"]. Is that
right?

b. DataSet

Only references to one table?

c. Binding source

d. DataSource.

If I could make all this in a console app, ¿where I could find a sample
using C# 2008, and an Access 2003?

Something such as:

SqlConnection cnn=Connection(ODBC,"prueba.mdb");
String sql="select * from users";
......

Thank you.




Cor Ligthert said:
Jordi,

Most probably in my idea
numero = usuarios.Tables.Count;
numero = usuarios.Tables[0].Count;

By the way I would not know a construction that would create this as a
Strongly Typed Dataset, while the construction created by you above should
give in normal situations (as you did not build your own collection around
a datatable) give an error.

Cor
 
Hello Cor,

I explain a little better the problem.

I've got a Form, with two EditBoxes, and a Button. When I click the button I
would like to check:

a. If in users table (database.mdb), exists any records.

b. A do/while to look for the user given in the Edit1Box1, and check the
password.

I try for this, the following:

1. Tools, Connect to Database, Access file, mdb. Ok, test succedded.

2. Add a bindingsource1, and created a datasource.

At this point, in my form there are a bindingsource1, and an
onlyxxxxxdataset2.

3. In datamember propertie for bindingsource I write name's table.

Here, adds a tableTableAdapter.

And now, here's my problem.

How could I check the number of records in the table?

Sorry, I tried again with this and it works...

private void button1_Click(object sender, EventArgs e)
{
int numero=onlyXXXXxSet2.PXXXXXXXs.Count;

}

private void Form3_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'onlyXXXXXX2.PXXXXX' table. You can move, or remove it, as needed.
this.XXXXTableAdapter.Fill(this.onlyXXXXXXSet2.PXXXXXXs);











Cor Ligthert said:
Jordi,

Most probably in my idea
numero = usuarios.Tables.Count;
numero = usuarios.Tables[0].Count;

By the way I would not know a construction that would create this as a
Strongly Typed Dataset, while the construction created by you above should
give in normal situations (as you did not build your own collection around a
datatable) give an error.

Cor
 
Jordi,

I understand it works now, you showed DataTable this is a property of the
non strongly typed DataSet, so that would have never OK. Any other name was
however possible as you show now.

Cor

JordiXip said:
Hello Cor,

I explain a little better the problem.

I've got a Form, with two EditBoxes, and a Button. When I click the button
I
would like to check:

a. If in users table (database.mdb), exists any records.

b. A do/while to look for the user given in the Edit1Box1, and check the
password.

I try for this, the following:

1. Tools, Connect to Database, Access file, mdb. Ok, test succedded.

2. Add a bindingsource1, and created a datasource.

At this point, in my form there are a bindingsource1, and an
onlyxxxxxdataset2.

3. In datamember propertie for bindingsource I write name's table.

Here, adds a tableTableAdapter.

And now, here's my problem.

How could I check the number of records in the table?

Sorry, I tried again with this and it works...

private void button1_Click(object sender, EventArgs e)
{
int numero=onlyXXXXxSet2.PXXXXXXXs.Count;

}

private void Form3_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'onlyXXXXXX2.PXXXXX' table. You can move, or remove it, as needed.
this.XXXXTableAdapter.Fill(this.onlyXXXXXXSet2.PXXXXXXs);











Cor Ligthert said:
Jordi,

Most probably in my idea
numero = usuarios.Tables.Count;
numero = usuarios.Tables[0].Count;

By the way I would not know a construction that would create this as a
Strongly Typed Dataset, while the construction created by you above
should
give in normal situations (as you did not build your own collection
around a
datatable) give an error.

Cor
 
Back
Top