C#连接SQl数据库问题
在做登录验证连接sql数据库时总是无法实现正常跳转,不知道什么原因
try
{
string strCon = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
//Label3.Text = strCon;
myConn = new SqlConnection(strCon);
myConn.Open();//连接数据库
string strcmd = "SELECT * FROM [student] where UserName='" + strname + "' and UserPwd='" + strpwd + "'";
SqlDataAdapter sda = new SqlDataAdapter(strcmd, myConn);
//Label3.Text = strCon;
sda.Fill(myDataset); //利用adapter对象把数据集塞到dataset中 (--------这里开始有问题了) //Label3.Text = strcmd;
if (myDataset.Tables[0].Rows[0] != null)
{
Label3.Text = myDataset.Tables["user"].Rows[0]["UserName"].ToString();
Session["UserName"] = TextBox1.Text;
Session["UserPwd"] = TextBox2.Text;
Response.Redirect("Default2.aspx?dealstr=登录成功");
}
}
catch (Exception e1)
{
Console.WriteLine(e1.ToString());
//Label3.Text = "连接出错!" + e1.ToString();
}
finally
{
myConn.Close();
}