CS0103: 当前上下文中不存在名称“mbid”

[复制链接]
查看11 | 回复1 | 2009-2-3 13:25:50 | 显示全部楼层 |阅读模式
源码如下:
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,怎么说不存在哦,忒奇怪了闹

回复

使用道具 举报

千问 | 2009-2-3 13:25:50 | 显示全部楼层
while (mydr.Read()) { int mbid =Convert.ToInt32( mydr.GetInt32(0).ToString()); } 改为 int mbid=0; while (mydr.Read()) { mbid =Convert.ToInt32( mydr.GetInt32(0).ToString()); }...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行