
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);',' 附近有语法错误.
从另一个页面的gridview中获取一条信息的ID值,但提示有语法错误,到底哪里错了啊?求大神搭救啊protectedvoidPage_Load(objectsender...
从另一个页面的gridview中获取一条信息的ID值,但提示有语法错误,到底哪里错了啊?求大神搭救啊
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ID"] != null)//修改操作
{
int nid = int.Parse(Request.QueryString["ID"].ToString());
//然后去取数据;
SqlConnection conn = new SqlConnection("Data Source=MICROSOF-0EB1C6;Initial Catalog=shijin;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select (infotitle,infomsg,lostadd,contactadd,contactperson,mobile,qq) from lostinfo where ID='"+ nid +"'", conn);
SqlDataReader Dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (Dr.Read())
{
this.TextBox1.Text =Dr["infotitle"].ToString();
this.TextBox2.Text =Dr["infomsg"].ToString();
this.TextBox3.Text =Dr["lostadd"].ToString();
this.TextBox4.Text =Dr["contactadd"].ToString();
this.TextBox5.Text =Dr["contactperson"].ToString();
this.TextBox6.Text =Dr["mobile"].ToString();
this.TextBox8.Text =Dr["qq"].ToString();
}
conn.Close(); 展开
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ID"] != null)//修改操作
{
int nid = int.Parse(Request.QueryString["ID"].ToString());
//然后去取数据;
SqlConnection conn = new SqlConnection("Data Source=MICROSOF-0EB1C6;Initial Catalog=shijin;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select (infotitle,infomsg,lostadd,contactadd,contactperson,mobile,qq) from lostinfo where ID='"+ nid +"'", conn);
SqlDataReader Dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (Dr.Read())
{
this.TextBox1.Text =Dr["infotitle"].ToString();
this.TextBox2.Text =Dr["infomsg"].ToString();
this.TextBox3.Text =Dr["lostadd"].ToString();
this.TextBox4.Text =Dr["contactadd"].ToString();
this.TextBox5.Text =Dr["contactperson"].ToString();
this.TextBox6.Text =Dr["mobile"].ToString();
this.TextBox8.Text =Dr["qq"].ToString();
}
conn.Close(); 展开
1个回答
展开全部
new SqlCommand("select (infotitle,infomsg,lostadd,contactadd,contactperson,mobile,qq) from lostinfo where ID='"+ nid +"'", conn);的select (infotitle,infomsg,lostadd,contactadd,contactperson,mobile,qq) from lostinfo where ID='"+ nid +"'"
括号去掉。
if (Dr.Read())
改为 while(Dr.Read())
括号去掉。
if (Dr.Read())
改为 while(Dr.Read())
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询