Login WinForm in C#
Hi..
can u give me a favor??
this is my sample coding..
private void btnLog_Click(object sender, System.EventArgs e)
{
if(SahForm()==false)
{
return;
}
InLogin();
}
private void InLogin()
{
string ConnStr = "server=localhost;database=Admin;trusted_connectio n=true";
string MySQL = "SELECT UserName, UserPass from Login WHERE UserName = '+ txtLog.Text + '" +
"AND UserPass = '+ txtPass.Text') ";
SqlConnection MyConnStr;
SqlCommand MyCmd;
SqlDataReader MyDR;
MyConnStr = new SqlConnection(ConnStr);
MyCmd = new SqlCommand(MySQL,MyConnStr);
MyConnStr.Open();
MyDR = MyCmd.ExecuteReader(System.Data.CommandBehavior.Cl oseConnection);
if(MyDR.Read())
{
MyDR.Close();
MyConnStr.Open();
MyDR = MyCmd.ExecuteReader(System.Data.CommandBehavior.Cl oseConnection);
Sistem sist = new Sistem();
//this.Hide();
sist.Show();
}
else
{
MessageBox.Show("ERROR");
MyDR.Close();
MyConnStr.Close();
}
}
private bool SahForm()
{
if(txtLog.Text == "" && txtPass.Text == "")
{
label4.Visible=true;
label5.Visible=true;
MessageBox.Show("Please enter Admin's ID and Password", this.Text);
txtLog.Focus();
return false;
else
{
return true;
}
}
but it'll return an error after we input the Admin's ID and Password. The error look like this...
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
So, please anybody help me.. =(
|