【求助】Fill: 应当为 SourceTable 名称输入一个非空字符串。参数名: srcTable
帮忙改改,谢谢了Fill: 应当为 SourceTable 名称输入一个非空字符串。参数名: srcTable 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: Fill: 应当为 SourceTable 名称输入一个非空字符串。参数名: srcTable
源错误:
| 行 33: conn.Open();行 34: DataSet ds = new DataSet();行 35: da.Fill(ds,tableName);行 36: 行 37: conn.Close(); |
void Page_Load(Object sender,EventArgs e)
{
if(!IsPostBack)
{
dg1.DataSource = CreateDataSource();
dg1.DataBind();
}
}
DataView CreateDataSource()
{
string c;
string selectStr ="";
string tableName ="";
if(Application["Subject"] =="英语")
{
tableName = "EnglishTest";
selectStr = "Select QuestionID,QuestionContent from EnglishTest";
}
if(Application["Subject"] =="数学")
{
tableName ="MathTest";
selectStr ="select QuestionID,QuestionContent from MathTest";
}
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter da = new SqlDataAdapter(selectStr,conn);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds,tableName);
conn.Close();
DataView dv = ds.Tables[tableName].DefaultView;
return dv;
}