一个登录界面。
web.config中:
<appSettings>
<add key="sqlcon" value="Data Source=(local);Database=guanli;Uid=sa;Pwd=Lch1980211"/>
</appSettings>Default.aspx中就2个文本框,一个写用户名,一个写密码,然后一个登录按钮:
已添加:
using System.Collections;
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
string username = Request["username"];
string userpwd = Request["userpwd"]; SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);
SqlCommand scd=new SqlCommand("Select count(*) from tb_user where username='"+ username +"' and userpwd='"+ userpwd +"'",strcon);
strcon.Open(); <-----出问题的地方
int i = Convert.ToInt32(scd.ExecuteScalar());
if (i>0) {
Response.Redirect("default.aspx");
}
else
{
Response.Write("<script>alert('wrong');history.back()</script>"); } }
请各位前辈指导菜鸟。
才自学ASP中。
多谢了!!!
web.config中:
<appSettings>
<add key="sqlcon" value="Data Source=(local);Database=guanli;Uid=sa;Pwd=Lch1980211"/>
</appSettings>Default.aspx中就2个文本框,一个写用户名,一个写密码,然后一个登录按钮:
已添加:
using System.Collections;
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
string username = Request["username"];
string userpwd = Request["userpwd"]; SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);
SqlCommand scd=new SqlCommand("Select count(*) from tb_user where username='"+ username +"' and userpwd='"+ userpwd +"'",strcon);
strcon.Open(); <-----出问题的地方
int i = Convert.ToInt32(scd.ExecuteScalar());
if (i>0) {
Response.Redirect("default.aspx");
}
else
{
Response.Write("<script>alert('wrong');history.back()</script>"); } }
请各位前辈指导菜鸟。
才自学ASP中。
多谢了!!!
这个key跟调用哪里不一样啊
连接串要放在 web.config的 <connectionStrings>节
ConfigurationManager.AppSettings["strcon"]
ConfigurationManager.AppSettings["sqlcon"]