Private void btn_login_click (Object sender, eventargs E)
{
// Sqlconnection CNN = new sqlconnection (); // use the sqlconnection member in the sqlclient class of the data interface
// CNN. connectionstring = "Server = 127.0.0.1; uid = sa; Pwd = admin; database = Factory"; // connect to the object string
String connstr = "Server = 127.0.0.1; uid = sa; Pwd = admin; database = Factory ";
String comment STR = "select user_name from users where user_name = @ user_name and user_ps = @ user_ps ";
Sqlconnection conn = new sqlconnection (connstr );
Sqlcommand cmd = new system. Data. sqlclient. sqlcommand (writable Str );
Sqlparameter [] parameters = {
New sqlparameter ("@ user_name", sqldbtype. nvarchar, 50 ),
New sqlparameter ("@ user_ps", sqldbtype. nvarchar, 50)
};
Parameters [0]. value = tb_user_name.text.tostring ();
Parameters [1]. value = tb_user_ps.text.tostring ();
Try
{
Cmd. Connection = conn;
Foreach (VAR item in parameters)
{
Cmd. Parameters. Add (item );
}
Cmd. Connection. open ();
Sqldatareader thisreader = cmd. executereader ();
while (thisreader. read ()
{< br> This. hide ();
form2 form2 = new form2 ();
// form2.windowstate = formwindowstate. maximized;
form2.show ();
}
}
Catch (exception ERR)
{
Console. writeline ("database read error" + err. Message );
}
Finally
{
// MessageBox. Show ("succeeded in reading the Database", "succeeded ");
Conn. Close ();
}
}