Unable to view message if wrong data enter or null data enter

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 43
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Unable to view message if wrong data enter or null data enter

 
0
  #11
Sep 23rd, 2008
One more thing... since this is about a log in thing... its expected that every username or adminID is unique therefore if will log-in you're selecting a specific user, thus, the query will return only one row on none.

So why do you need to loop? I think it's unnecessary.

Hope this would help.

regards...
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 14
Reputation: shxrainz is an unknown quantity at this point 
Solved Threads: 0
shxrainz shxrainz is offline Offline
Newbie Poster

Re: Unable to view message if wrong data enter or null data enter

 
0
  #12
Sep 24th, 2008

I still got an error

after i editing ur code by declaring a new dataTable object that you been missing then an error occurs :

Error 1 'System.Data.OleDb.OleDbDataAdapter' does not contain a definition for 'Close'

this is the coding part that i edited


string admId = textBox1.Text;
string passw = textBox2.Text;
string strqry = string.Format(@"SELECT AdminId,Password
FROM Admin
WHERE AdminId ={0} AND
Password = {1}", admId, passw);

OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbStd.mdb;");
OleDbDataAdapter adapter = null;
try
{
DataTable dt = new DataTable();
conn.Open();
adapter = new OleDbDataAdapter(strqry, conn.ConnectionString);
adapter.Fill(dt);

if (dt.Rows.Count >0)
{
string username = dt.Rows[0][0].ToString();
string pw = dt.Rows[0][1].ToString();

if (username == admId && pw == passw)
{
MessageBox.Show("Welcome!");
}
else
{
MessageBox.Show("Access Denied.");
}
}
else
{
MessageBox.Show("Access Denied.");
}

}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
finally
{
adapter.Dispose();
adapter.Close();
conn.Close();
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 14
Reputation: shxrainz is an unknown quantity at this point 
Solved Threads: 0
shxrainz shxrainz is offline Offline
Newbie Poster

Re: Unable to view message if wrong data enter or null data enter

 
0
  #13
Sep 24th, 2008

thanks jireh...
i already solve the problem..
it just b'coz of no '{0}' and '{1}' in the coding..
It works!

Thank a lot..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC