我用c#链接sql server2008数据库时出现了,请大神们帮解决下
下面是代码:usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingSy...
下面是代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "server=SU12;database= SCDB; trusted_connection=true";
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("select count(*) from student where usersName=@usersName and classID= @pwd", con);
com.Parameters.Add("@usersName", SqlDbType.VarChar).Value = Name.Text;
com.Parameters.Add("@pwd", SqlDbType.VarChar).Value =pwd.Text;
con.Open();
int count = (int)com.ExecuteScalar();
if (count <= 0)
{
Label1.Text = "用户名密码错误";
}
else
{
Label1.Text = "登陆成功";
}
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource=reader;
GridView1.DataBind();
reader.Close();
con.Close();
}
} 展开
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "server=SU12;database= SCDB; trusted_connection=true";
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("select count(*) from student where usersName=@usersName and classID= @pwd", con);
com.Parameters.Add("@usersName", SqlDbType.VarChar).Value = Name.Text;
com.Parameters.Add("@pwd", SqlDbType.VarChar).Value =pwd.Text;
con.Open();
int count = (int)com.ExecuteScalar();
if (count <= 0)
{
Label1.Text = "用户名密码错误";
}
else
{
Label1.Text = "登陆成功";
}
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource=reader;
GridView1.DataBind();
reader.Close();
con.Close();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询