哦,public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String name = this.textBox1.Text;
String password = this.textBox2.Text;
//获得数据库连接字符串Data Source=.;Initial Catalog=tempdb;Integrated Security=True
String conn = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
//创建SqlConnection
SqlConnection connect = new SqlConnection(conn);
String Sql = String.Format("Select * form tempdb Londing where usemer ='{0}'and password='{1}'", name, password);
//创建SqlCommand对象
SqlCommand command = new SqlCommand(Sql, connect);
connect.Open();//注:打开数据库连接要在创建command对象之后执行
int num = Convert.ToInt32(command.ExecuteScalar());
try
{
if (num > 0)
{
MessageBox.Show("登陆成功!");
}
else
{
MessageBox.Show("账户或密码错误!");
}
}
catch(Exception ex)
{
MessageBox.Show("异常!"+ex);
}
finally
{
connect.Close();
}
这样?但是还是错的呀 |