用C#语言实现一个简单登录的有关数据库连接的问题
验证用户名密码部分代码:
try
{
SqlConnection conn = new SqlConnection("server=.;database=Loading;Trusted_Connection=true");
SqlCommand cmd = new SqlCommand("select count(*) from UserTable where 用户名='" + userid + "'and 密码='" + userpassword + "'", conn);
conn.Open();
int count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (count > 0)
{
Response.Redirect("success.aspx");
}
conn.Close();
}
连接类:
public class Connection
{
public static SqlConnection CurrentConnection
{
get
{
return new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AccessConnectString"].ToString());//从web.config中读取数据库连接字符串
}
private set
{
}
}
我用的是Access数据库。
点击登录按钮后无法连接数据库。求大虾指点。