private void buttonOK_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
string connectionString = "Data Source=USERUSE-6G3K4SP;Initial Catalog=Database;Integrated Security=True";
conn.ConnectionString = connectionString;
conn.Open();
try
{
string id, pwd;
id = textBox1.Text;
pwd = textBox2.Text;
string select_login="select * from Enter where User='" + id + "' and Userpwd'"+ pwd +"' and Power='0'";
SqlCommand user_empty = new SqlCommand(select_login,conn);
SqlDataReader myReader_rows = user_empty.ExecuteReader();
//读取行信息数据
bool rows=myReader_rows.HasRows;
myReader_rows.Close();
if(rows == true)
{
MainForm a = new MainForm();
a.MEnteritem.Enabled = false;
a.MDataitem.Enabled = false;
a.MHitem.Enabled = false;
a.MTitem.Enabled = false;
a.MResearchitem.Enabled = true;
a.Pwditem.Enabled = true;
this.Close();
}
else
{
MessageBox.Show("验证失败,请核对后再试!", "错误");
}
conn.Close();
}
catch
{
MessageBox.Show("用户名或者密码错误!");
}
这是我登入按钮的代码
{
SqlConnection conn = new SqlConnection();
string connectionString = "Data Source=USERUSE-6G3K4SP;Initial Catalog=Database;Integrated Security=True";
conn.ConnectionString = connectionString;
conn.Open();
try
{
string id, pwd;
id = textBox1.Text;
pwd = textBox2.Text;
string select_login="select * from Enter where User='" + id + "' and Userpwd'"+ pwd +"' and Power='0'";
SqlCommand user_empty = new SqlCommand(select_login,conn);
SqlDataReader myReader_rows = user_empty.ExecuteReader();
//读取行信息数据
bool rows=myReader_rows.HasRows;
myReader_rows.Close();
if(rows == true)
{
MainForm a = new MainForm();
a.MEnteritem.Enabled = false;
a.MDataitem.Enabled = false;
a.MHitem.Enabled = false;
a.MTitem.Enabled = false;
a.MResearchitem.Enabled = true;
a.Pwditem.Enabled = true;
this.Close();
}
else
{
MessageBox.Show("验证失败,请核对后再试!", "错误");
}
conn.Close();
}
catch
{
MessageBox.Show("用户名或者密码错误!");
}
这是我登入按钮的代码