views:

91

answers:

1
A: 

fMay be something like this, create a connection and than read from your access file.

 OleDbConnection conn;
    OleDbCommand comm;
    OleDbDataReader dr;
    conn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\db1.mdb");
    comm = new OleDbCommand("Select * from Table1 where loginId =@id and password=@pass",conn);
    comm.Parameters.Add(new OleDbParameter("@id",System.Data.oleDbType.NVarChar,20, "loginID"));
    comm.Parameters.Add(new OleDbParameter("@pass",System.Data.oleDbType.NVarChar,20, "password")); 

    conn.Open();
    dr = comm.ExecuteReader();
    conn.Close();
if(dr.hasrows)
{
//login success
}
else
 //login fail

Than you can authenticate by using dr against the user input. Put this above your commented line.

Thurein
Hello... how to authenticate by using dr against the user input? Thanks for your help!
Char
You need to change the select query accordingly based on your user table and append a where clause to check (authenticate) the loginID and Password. Then use dr.HasRows to see whether the user exist or not.
Thurein
sorry to say that, I dun really understand =\ any step by step method so i can follow? thanks agn, and sorry...
Char
ok, see the code above, I have updated, actually, its doing the following steps --connect to access using oledb connection string.-use the select statement with where clause to query the login user's -information is exist or not.-Execute the statement -Check the select statement is returning any result. If returing result set got rows means the authentication is success other wise its fail because the user information entered was not match.
Thurein
Hello, this code couldn't work on my visual studio...comm.Parameters.Add(new OleDbParameter("@id",System.Data.oleDbType.NVarChar,20, "loginID")); comm.Parameters.Add(new OleDbParameter("@pass",System.Data.oleDbType.NVarChar,20, "password"));oleDbType was underline red. Its error is: "The type or namespace name 'oleDbType' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
Char
anyways I've updated the codes that I've done on my question...
Char
but when I remove the System.Data.oleDbType.NVarChar,20, it works perfectly fine.... But when I type the correct info in that time it prompt me Login Failed...
Char
its depends on the data type in side your access, so refer to your access file. You need to place a break point and debug as well. You also need to refer to the system.data.oledb.
Thurein
I already define the system.data.oledb already, using System.Data.OleDb; still have the red line at System.Data.oleDbType.NVarChar,20... and sorry to ask what you mean by place a break point and debug?
Char
just change from System.Data.oleDbType.NVarChar,20 to OleDbType.VarChar ,20 in both line and you need to refer to your acess file for the correct datatype "System.Data.oleDbType.NVarChar,20," is just an example.
Thurein
Now i have one more error... which is on dr = comm.ExecuteReader(); it says: Parameter @id has no default value.
Char
I think you need to replace with this - new OleDbParameter("@id",txtUserId.Text) //txtUserId is your text box.
Thurein
Yep also for the next @pass parameter :)
Thurein
Hello, thanks for your help! I manage to solve my problem! THANKS!
Char
u r welcome :).
Thurein