using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connString = @"Data Source=k208-38\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
conn.Open();// 打开数据库连接
//string name = tdname.Text.Trim();//获取用户名控件文本,且去掉空格
//string pwd = tdpwd.Text.ToString().Trim();
//string sql = "select count(*) from admin where LoginID = '" + name + "' and LoginPwd='" + pwd + "'";
string sql = "select count(*) from admin where LoginID =@ID and LoginPwd=@Pwd";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@ID", tdname.Text);
cmd.Parameters.AddWithValue("@Pwd", tdpwd.Text);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
Form2 f = new Form2();
f.Show();
}
else
{
MessageBox.Show("账户密码错误");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connString = @"Data Source=k208-38\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
conn.Open();// 打开数据库连接
//string name = tdname.Text.Trim();//获取用户名控件文本,且去掉空格
//string pwd = tdpwd.Text.ToString().Trim();
//string sql = "select count(*) from admin where LoginID = '" + name + "' and LoginPwd='" + pwd + "'";
string sql = "select count(*) from admin where LoginID =@ID and LoginPwd=@Pwd";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@ID", tdname.Text);
cmd.Parameters.AddWithValue("@Pwd", tdpwd.Text);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
Form2 f = new Form2();
f.Show();
}
else
{
MessageBox.Show("账户密码错误");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}