源码如下:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection(constr);
myconn.Open();
SqlCommand mycom = new SqlCommand("select * from member where mb_name='" + Session["username"].ToString().Trim() + "'", myconn);
SqlDataReader mydr = mycom.ExecuteReader();
while (mydr.Read())
{
int mbid =Convert.ToInt32( mydr.GetInt32(0).ToString());
}
SqlCommand mycommand = new SqlCommand("insert into comment(comment,a_id,mb_id) values('" + TextBox1.Text.ToString() + "','" + Request.QueryString["a_id"].ToString() + "'," + mbid + ")", myconn);
mycommand.ExecuteNonQuery();
myconn.Close();
}
错误提示:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS0103: 当前上下文中不存在名称“mbid”
源错误:
行 57:
int mbid =Convert.ToInt32( mydr.GetInt32(0).ToString());
行 58:
}
行 59:
SqlCommand mycommand = new SqlCommand("insert into comment(comment,a_id,mb_id) values('" + TextBox1.Text.ToString() + "','" + Request.QueryString["a_id"].ToString() + "'," + mbid + ")", myconn);
行 60:
mycommand.ExecuteNonQuery();
行 61:
myconn.Close();
明明取出了mbid,怎么说不存在哦,忒奇怪了闹
|