Request.QueryString.ToString()的问题
private void show()
{
string id=Request.QueryString.ToString();
//Response.Write(id);
string strsql="select * from article where articleid="+Convert.ToInt16(id);
SqlConnection sqlcon=new SqlConnection("Server=.;uid=sa;pwd=123;Database=users");
SqlCommand sqlcom=new SqlCommand(strsql,sqlcon);
sqlcon.Open();
SqlDataReader sqldr=sqlcom.ExecuteReader();
if(sqldr.HasRows)
{
while(sqldr.Read())
{
Response.Write(sqldr["title"]+"<br>");
Response.Write(sqldr["content"]+"<hr>");
}
}
sqldr.Close();
sqlcon.Close();
}
红线部分有错吗?没错吧,但为什么提示
行 50: string id=Request.QueryString.ToString();行 51: // Response.Write(id);行 52: string strsql="select * from article where articleid="+Convert.ToInt16(id);行 53: SqlConnection sqlcon=new SqlConnection("Server=.;uid=sa;pwd=123;Database=users");行 54: SqlCommand sqlcom=new SqlCommand(strsql,sqlcon);private void show() { if(!string.IsNullOrEmpty(Request.QueryString["id"].Trim())) { string id=Request.QueryString["id"].ToString(); string strsql="select * from article where articleid="+Convert.ToInt16(id); SqlConnection sqlcon=new SqlConnection("Server=.;uid=sa;pwd=123;Database=users"); SqlCommand sqlcom=new SqlCommand(strsql,sqlcon); sqlcon.Open(); SqlDataReader sqldr=sqlcom.ExecuteReader(); if(sqldr.HasRows) { while(sqldr.Read()) { Response.Write(sqldr["title"]+" <br>"); Response.Write(sqldr["content"]+" <hr>"); } } sqldr.Close(); sqlcon.Close(); }}