| | |
Unable to view message if wrong data enter or null data enter
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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...
So why do you need to loop? I think it's unnecessary.
Hope this would help.
regards...
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: Sep 2008
Posts: 14
Reputation:
Solved Threads: 0
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();
}
![]() |
Other Threads in the C# Forum
- Previous Thread: Graph in 2D
- Next Thread: SQL Server Connection how to's
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation visualstudio webbrowser windows winforms wpf xml





