此例是根据用户名和学号作为登陆信息的:
public partial class Form1 : Form
{
//定义接收用户名和学号的字符串
public string txtName;
public string txtSno;
public Form1()
{
InitializeComponent();
}
//定义连接
SqlConnection conn = new SqlConnection(@"Data Source=./sqlexpress;Initial Catalog=student;Integrated Security=True");
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox2.Text == "")
{
MessageBox.Show("请输入用户名和学号!");
return;
}
try
{
txtName = textBox1.Text.Trim();
txtSno = textBox2.Text.Tri