Thursday, 15 August 2013

ms access - how to add data in a database to variable in C# for Login -



ms access - how to add data in a database to variable in C# for Login -

i need create login , want create connecting database.

oledbcommand cm; oledbconnection cn = new oledbconnection(); cn.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\lakshanp\documents\c sharp work database\adhideit.accdb"; cm = new oledbcommand("select usnam,paswd signin usnam = @a , paswd = @b", cn); cm.parameters.addwithvalue("@usnam", textbox1.text.tostring()); cm.parameters.addwithvalue("@paswd", textbox2.text.tostring()); string un; string pw; cn.open(); oledbdatareader dr = cm.executereader(); if (textbox1.text == "usnam" & textbox2.text == "paswd") { new form1().show(); } else { messagebox.show("invalied username or password"); }

if want info executed query require read info data reader i.e. dr.read(), check if has rows means username , password valid, else invalid.

oledbcommand cm; oledbconnection cn = new oledbconnection(); cn.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\lakshanp\documents\c sharp work database\adhideit.accdb";

cm = new oledbcommand("select usnam,paswd signin usnam = @usnam , paswd = @paswd", cn); cm.parameters.addwithvalue("@usnam", textbox1.text.tostring()); cm.parameters.addwithvalue("@paswd", textbox2.text.tostring()); string un; string pw; cn.open(); oledbdatareader dr = cm.executereader(); if (dr.read()) { new form1().show(); } else { messagebox.show("invalied username or password"); }

c# ms-access

No comments:

Post a Comment