我用Windows身份验证登录的Microsoft SQL Server 用的是计算机名加\SQLEXPRESS
我在C#也连接上了
运行时输入账号和密码就应该出现
可是我的会一直卡在输入账号与密码的界面
过一会就会报错
这个是代码,帮我看一下我该怎么改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 学生考勤系统
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//获取链接
public SqlConnection GetCon()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Server=.;Trusted_Connection=SSPI;DataBase=xskqDB";
return con;
}
private void button1_Click(object sender, EventArgs e)
{
string name = this.textBox1.Text.Trim();
string pwd = this.textBox2.Text.Trim();
string sqlstr = "select * from suser where name='" + name + "' and password= '" + pwd + "'";
SqlConnection con = GetCon();
con.Open();
SqlDataAdapter sad = new SqlDataAdapter(sqlstr, con);
DataTable dt1 = new DataTable();
sad.Fill(dt1);
if(dt1.Rows.Count>0)
{
//登录主窗体
this.Hide();
mainForm mf = new mainForm();
mf.Show();
}
else
{
//提示错误,清空输入框
MessageBox.Show("用户名或密码错误,是否重新输入");
this.textBox1.Text = "";
this.textBox2.Text = "";
}
con.Close();
}
}
}