private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = null;
try
{
con = new SqlConnection(
"Data Source=llll-PC;Initial Catalog=yonghu;User ID=sa;Password=123");
string sql = "select * from Table_1 where Table_1.user=@name and Table_1.pwd=@pwd";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@name", textBox1.Text);
cmd.Parameters.AddWithValue("@pwd", textBox2.Text);
con.Open();
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (textBox1.Text=="llll"&&textBox2.Text=="123")
{
MessageBox.Show("成功!");
Form3 f3 = new Form3();
f3.Show();
}
else
{
MessageBox.Show("失败!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}