Hi everyone
Am new in the software development world and am trying to come up with a login application that checks username and password from the database.Please if anyone can give me a heads up i would really appreciate
thnx
jerry
Hi everyone
Am new in the software development world and am trying to come up with a login application that checks username and password from the database.Please if anyone can give me a heads up i would really appreciate
thnx
jerry
In fact if you have a quick look through some of the other threads you'll find how others have approached it.
You'll need 2 forms usually, a connection to the db.
What code do you have so far?
Determine first what database you will use so that you can determine what connection you will have to use.
Then try to solve it in your own and after your coding you will have a problem then post your code here so we could help.
post your code that you have been done so far..
so then we will know what kind of problem that you got..
create a login form with 2 text box and one command button and a mdb file that store user name and password. I send you some code. Try to understand this code.
using System;
using System.Data;
using System.Data.OleDb;
public class Login
{
public string LoginId;
public string PassWord;
public bool
{
OleDbConnection cn = new OleDbConnection(@"provider = microsoft.jet.OleDb.4.0; data source=c:\dotnet\WinApp\LoginManager\LoginId.mdb");
OleDbCommand cmd = new OleDbCommand("select * from LoginId where UserId = ?",cn);
OleDbDataReader r;
cmd.Parameters.AddWithValue("1",LoginId);
cn.Open();
r=cmd.ExecuteReader();
if(r.Read())
{
string a = r.GetString(1);
if(a==PassWord)
{ cn.Close();
return true;
}
}
else
{
cn.Close();
return false;
}
}
}
i think u get some hint. if not then tell your problems.
or this...
private void cmdOk_Click(object sender, EventArgs e)
{
string LoginId = txtUserID.Text;
string PassWord = txtPassword.Text;
string sql = string.Format(@"select *
from tblUser
where UserId = '{0}'
and Password = '{1}' ;", LoginId, PassWord);
OleDbConnection oConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False");
oConn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, oConn.ConnectionString);
DataSet ds = new DataSet();
adapter.Fill(ds, "Table");
if (ds.Tables[0].Rows.Count > 0)
{
MessageBox.Show("Log-in succeeded.");
}
else
{
MessageBox.Show("Access denied.");
}
adapter.Dispose();
oConn.Close();
}
Hope it would help.
regards.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.