ASP.net中对SQL查询语句 最简单的是这样吗 ASP.NET有没有更方便的方法呢?
stringusername=textbox1.text;stringpassword=textbox2.text;stringsetting=Convert.ToStr...
string username=textbox1.text;
string password=textbox2.text;
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["mysql"]);
SqlConnection myconn = new SqlConnection(setting);
myconn.Open();
string strsql = "select * from [Login] where Username='" + username + "' and Password='" + password + "'";
SqlCommand mycmd = new SqlCommand(strsql, myconn);
SqlDataReader mydr = mycmd.ExecuteReader();
try
{
if (mydr.Read())
{
//登录成功
}
else
{
//登录失败
}
}
finally
{
mydr.Close();
myconn.Close();
}
} 展开
string password=textbox2.text;
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["mysql"]);
SqlConnection myconn = new SqlConnection(setting);
myconn.Open();
string strsql = "select * from [Login] where Username='" + username + "' and Password='" + password + "'";
SqlCommand mycmd = new SqlCommand(strsql, myconn);
SqlDataReader mydr = mycmd.ExecuteReader();
try
{
if (mydr.Read())
{
//登录成功
}
else
{
//登录失败
}
}
finally
{
mydr.Close();
myconn.Close();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询