Bosses, please answer, thank you
CodePudding user response:
Private void btnsubmit_Click (object sender, EventArgs e){
Try
{
If (txtusername. Text=="")
{
MessageBox. Show (" user name cannot be empty ");
}
The else
{
If (txtpassword. Text=="")
{
MessageBox. Show (" password cannot be empty ");
}
The else
{
String username=txtusername. Text;//gain username
String password=txtpassword. Text;//gain password
String conn=@ "server=LAPTOP - A4EP75C2; Integrated security=true ";
//connnection string
SqlConnection connection=new SqlConnection (conn);
//create the conn
Connection. The Open ();
//open the conn
String SQL=the string. Format (" select count (*) from SQLstudent where sname='{0}' and password='{1} ", username, password);
//find the data you want from the database
SqlCommand command=new SqlCommand (SQL, connection);
//keep the data a moment
Int I=the Convert. ToInt32 (command. ExecuteScalar ());
//execution records returned after rows
If (I & gt; 0)
//if greater than 1 that records exist, login success
{
MessageBox. Show (" login successfully, welcome!" );
This. Hide ();
}
The else
{
MessageBox. Show (" the user name or password error!" );
}
Connection. The Close ();
}
}
}
The catch (Exception ex)
{
MessageBox. Show (" exception error "+ ex);
}
}
CodePudding user response:
Very clear, SQLstudent table notDid you connect the wrong database,
CodePudding user response:
String conn=... This line is not specified in which library useCodePudding user response:
Select count (*) from SQLstudent where sname='{0}' and password='{1}' the table name is invalid, SQLstudent, go to the database