请各位帮忙看一我这段传值方面的代码,我急要,谢谢!
string username=Request.QueryString["username"].ToString();关键是这句,老是取不到值(未将对象引用到对象的实例的错误信息),我用HTM页面跟ASP.NET界面相结合来做的,我的登录界面有HTM页面和ASPX页面,在HTM页面的话进行界面设置且设置为GET方法来获取,在ASPX页面的PAGE_LOAD事件中写:
string username=Request.QueryString["username"].ToString();
string userpwd=Request.QueryString["userpwd"].ToString();
// string dbPath=System.Configuration.ConfigurationSettings.AppSettings["lyb"];
// //定义数据库连接字符串
// string ACconnStr="Provider=Microsoft.Jet.Sql.4.0;Data Source="+Server.MapPath(dbPath);
//创建数据库连接对象
//SqlConnection ACconn=db.createconnection();
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["lyb"]);
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from admin where username='"+username+"' and userpwd='"+userpwd+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Session["name"]=true;
Response.Redirect("OK.aspx?username="+username+"");
}
else
{
Response.Redirect("fail.htm");
}
}
就会出现未将对象引用到对象的实例的错误信息,请各位帮忙一下,我急要,谢谢!
--------------------编程问答-------------------- --------------------编程问答-------------------- http://..../aaa.aspx?username=""
if(Request.QueryString[ "username "]!=null ||Request.QueryString[ "username "]!="")
{
string username=Request.QueryString[ "username "].ToString();
}
取值的时候判断下 --------------------编程问答-------------------- 确认你是否真的传了值过去:?username=..&userpwd=..;
Request.QueryString["username"]本身就是字符串,不用再加.ToString()转;
如果不传参则要判断参数是否存在:
if(Request.QueryString["username"] != null)
{
string username=Request.QueryString["username"];
}
补充:.NET技术 , ASP.NET