473,387 Members | 3,821 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,387 software developers and data experts.

return hasrows OleDbDataReader

134 100+
Hello all,

I have the following code in class SQL

Expand|Select|Wrap|Line Numbers
  1. public void ExecuteReadQuery(string ReadQuery)
  2.         {
  3.             if (dbconn == null)
  4.                 return;
  5.  
  6.             OleDbDataReader dr;
  7.             OleDbCommand cmd = new OleDbCommand();
  8.             dr = cmd.ExecuteReader();
  9.  
  10.             if (dr.HasRows == true)
  11.                 return;
  12.  
  13.             try
  14.             {
  15.                 dbconn.Open();
  16.             }
  17.             catch (Exception ex)
  18.             {
  19.                 dbconn.Close();
  20.                 throw new CSMException(ex.Message, ex.Message);
  21.             }
  22.             finally
  23.             {
  24.                 dbconn.Close();
  25.             }
  26.         }
But how can I make sure that if the "hasrows" actually returns rows. My form (which is calling on the sql class) gets some kind of a signal. And he knows that the login data is correct and he can send you to the main menu?
The code of the login form is posted below:

Expand|Select|Wrap|Line Numbers
  1. SQL sql = new SQL();
  2.                 sql.ExecuteReadQuery("SELECT Username, Password FROM Users WHERE Username = "+user + "AND pass = "+pass);
Expand|Select|Wrap|Line Numbers
  1. if ()
  2.                 {
  3.                     using (MainMenu MainMenu = new MainMenu())
  4.                     {
  5.                         Hide();
  6.                         MainMenu.ShowDialog();
  7.                         Environment.Exit(0);
  8.                     }
  9.                 }
Both codes are placed in my login form.
Mar 7 '12 #1

✓ answered by r035198x

1.) Open the connection before creating the command on it.
2.) Write the sql in the SQL class rather than in the GUI code.
3.) Create a method called, say IsValidUser that takes the user named and password and returns a boolean value.
4.) In the method use
Expand|Select|Wrap|Line Numbers
  1. return dr.HasRows;
to indicate that you have rows and so the user is valid.
5.) Your GUI code then does if(sql.IsValidUser("someUser", "somePassword")) { ....

1 3229
r035198x
13,262 8TB
1.) Open the connection before creating the command on it.
2.) Write the sql in the SQL class rather than in the GUI code.
3.) Create a method called, say IsValidUser that takes the user named and password and returns a boolean value.
4.) In the method use
Expand|Select|Wrap|Line Numbers
  1. return dr.HasRows;
to indicate that you have rows and so the user is valid.
5.) Your GUI code then does if(sql.IsValidUser("someUser", "somePassword")) { ....
Mar 7 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
3
by: Buddy | last post by:
Hello, How do I get the number of row retrieved on a SELECT query when using OleDbDataReader? I am using Framework 1.0.
10
by: Dion Heskett | last post by:
I wish to supply the formating as a parameter, I have tried OleDbDataReader but get a null ref. just can't seem to get this to work. I think this has something to do with ExecuteReader. also...
1
by: charliewest | last post by:
Is there a .Net Compact Framework equivalent in the system.data.sqlserverce namespace of the .Net Framework system.data.sqlclient DataReader object's "Has.Rows" method? For example: ...
2
by: gjtired | last post by:
Hi, I can't figure out why my HasRows code is always true. Below is a snippet of my code. sqlConnection1.Open(); //Check that quiz name is not a duplicate during the Create(0)task string...
1
by: Claudia Fong | last post by:
Hi, I'm using the oleDbDataReader HasRows properties to detect wheter my table contains a record with the parameter below: oleDbConnection1.Close(); objreturnst.Parameters.Value =...
0
by: Steve1 via DotNetMonster.com | last post by:
Hi all, I''ve created an OleDbDataReader that will contain the number of records that the used SQL query will return. I'm then using a while loop to loop while the OleDBDataReader object has...
1
by: Rick | last post by:
I have found the HasRows member of the OleDbConnection. This is very nice to tell me if I have any data coming but what if I want to see how many rows of data I have. Is there a similar member to...
1
by: DotNetDev | last post by:
Hi, I have a function.... private bool myfunction() { SqlDataReader myReader = CommandObject.ExecuteReader(); if (myReader.HasRows) return true; else
0
by: ashes | last post by:
Hi, i created a register form on a website. The information from the form has to go in the customer table in a database in MS Access. the information is going into the table perfectly. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.