473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 3643
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid...
2
by: JS | last post by:
I'm trying to create a data layer and having problems returning a DataSet from my code that's in a class module. Please forgive me. I'm new to C# (VB'er). I decided to create my data layer in...
2
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid...
0
by: Mike | last post by:
Hi, I am trying to solve a problem with a DataSet issue I am having. In my app the user selects certain options and based on those options it goes out to the db to get data based on those...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
2
by: Jeff Brown | last post by:
OK i have came to the conclusion that since this app will be run on multiple computers that loading a complete database and then updating on exit is a moot point. I have tried several ideas...
4
by: markerussell | last post by:
I have a question, in that if i have an application is it better to have one dataset per data adapter, ie daCustomerTable -> dsCustomer, daOrders -> dsOrders etc. or to say have a couple of dataset...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
2
by: JT | last post by:
I have an SQL database with one table in it. I want to load the table into a DataSet, add new records to the DataSet, then commit the changes back to the database. Using C#.NET, the following...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.