获取Exception必须声明标量变量

获取Exception必须声明标量变量

本文介绍了获取Exception必须声明标量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在gridview中指定教师的所有记录



代码如下:

i am trying to all records of specified teacher in gridview

code is given below

String tea_id12 =Convert.ToString(TextBox1.Text);

SqlDataAdapter da = new SqlDataAdapter("select * from Question where  Teacher_id=@tea_id12", con);
DataSet ds = new DataSet();
da.Fill(ds, "questions");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
//in my Question table colums are question_id,teacher_id,teacher_question,teacher_answer

//i tried for this also

String tea_id12 = Convert.ToString(TextBox1.Text);

SqlDataAdapter da = new SqlDataAdapter("select * from Question,Teacher where Question.Teacher_id=Teacher.Teacher_id and Teacher_id=@tea_id12", con);
DataSet ds = new DataSet();
da.Fill(ds, "questions");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

推荐答案

String tea_id12 = Convert.ToString(TextBox1.Text);
  
 SqlDataAdapter da = new SqlDataAdapter("select * from Question,Teacher where Question.Teacher_id=Teacher.Teacher_id and Teacher_id= @tea_id12", con);

da.SelectCommand.Parameters.AddWithValue("tea_id12 ","" + tea_id12 + "");DataSet ds = new DataSet();
 da.Fill(ds, "questions");
 GridView1.DataSource = ds.Tables[0];
 GridView1.DataBind();


这篇关于获取Exception必须声明标量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:27