469,356 Members | 2,629 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Dataset question

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?
Nov 16 '05 #1
6 3455
Keith Smith wrote:
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/
Nov 16 '05 #2
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Keith Smith" <ke*********@verizon.net> wrote in message
news:5qqLd.2246$0O4.1917@trnddc03...
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?

Nov 16 '05 #3
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
Nov 16 '05 #4
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...
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

Nov 16 '05 #5
> 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'."
Nov 16 '05 #6
Hi,
ExecuteScalar is a member of OleDbCommand, not of DataAdapter
Cheers,

"Keith Smith" <ke*********@verizon.net> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
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'."

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Simon Harvey | last post: by
2 posts views Thread by Simon Harvey | last post: by
reply views Thread by Mike | last post: by
15 posts views Thread by JIM.H. | last post: by
4 posts views Thread by markerussell | last post: by
22 posts views Thread by Arne | last post: by
2 posts views Thread by JT | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.