Dataset question

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

For authentication purposes I query my Access database using a Username and
Password. If the dataset turns up empty then the user does not have access.
If it shows up with a value in the dataset then the user is authenticated.

The problem I am having is that when I count the number of entries in my
dataset it always shows up as "1". Even when I query the database with
values that aren't in the database.

I am using this code...
int RecordCount=dtSet.Tables.Count;

Is there a better way to count the entries in a dataset? Or perhaps a
better way of authentication all together?
 
Keith said:
The problem I am having is that when I count the number of entries in my
dataset it always shows up as "1". Even when I query the database with
values that aren't in the database.

I am using this code...
int RecordCount=dtSet.Tables.Count;
The code in you example assigns the number of tables within the DataSet
to the RecordCount variable. You need to use the number of rows in the
result table.
Presuming you've only got one table in your DataSet you can do this:
int RecordCount=dtSet.Tables[0].Rows.Count;

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Hi,

IMO this is a very ineficient way of doing it, what if instead of returning
a dataset you just return a number SqlCommand.ExecutyScalar

It's more efficient and less confusing


cheers,
 
Ignacio,
IMO this is a very ineficient way of doing it, what if instead of
returning a dataset you just return a number SqlCommand.ExecutyScalar

It's more efficient and less confusing
I agree with one little exception that is when you need after the
verification the data from the user.

Cor
 
Hi,


If you need to have the ID of the user you could return it. you would have
to make some convension to denote a "not found" user . If your users has an
integer ID then -1 or 0 could denote a not valid user.

Later you could use the ID to retrieve the user information if needed

cheers,
 
IMO this is a very ineficient way of doing it, what if instead of
returning a dataset you just return a number SqlCommand.ExecutyScalar

It's more efficient and less confusing

Ignacio,

Thanks for your comments. I did some research on the ExecutyScalar command
(I assume your "Executy" is just a type-o) and I can't seem to get it to
work with an MS Access database. Is this possible? Here is my code incase
you have a quick answer...

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\mydata.MDB";
string strSQL = "SELECT * FROM sec WHERE (u='" + textBox1.Text + "' AND p='"
+ textBox2.Text + "');" ;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbDataAdapter myCmd = new OleDbDataAdapter( strSQL, myConn );
myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "sec" );
int xx = (int) myCmd.ExecuteScalar();

The error I get is "...OleDbDataAdapter does not contain a definition for
'ExecuteScalar'."
 
Hi,


ExecuteScalar is a member of OleDbCommand, not of DataAdapter


Cheers,
 
Back
Top