string id=Request.QueryString["id"];
id=id.Substring(0,2);
string str="select tablename from industry_table where induaid='"+id+"'";
string sql="select * from '(" + str + ")'";
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,conn);
sqlAdapter.Fill(ds,"str");
运行的时候出错
“/Web”应用程序中的服务器错误。
--------------------------------------------------------------------------------第 1 行: '(select tablename from industry_table where induaid=' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '(select tablename from industry_table where induaid=' 附近有语法错误。源错误:
行 47: DataSet ds = new DataSet();
行 48: SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,conn);
行 49: sqlAdapter.Fill(ds,"str");
行 50:
行 51: DataView dataview = new DataView();
id=id.Substring(0,2);
string str="select tablename from industry_table where induaid='"+id+"'";
string sql="select * from '(" + str + ")'";
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,conn);
sqlAdapter.Fill(ds,"str");
运行的时候出错
“/Web”应用程序中的服务器错误。
--------------------------------------------------------------------------------第 1 行: '(select tablename from industry_table where induaid=' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '(select tablename from industry_table where induaid=' 附近有语法错误。源错误:
行 47: DataSet ds = new DataSet();
行 48: SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,conn);
行 49: sqlAdapter.Fill(ds,"str");
行 50:
行 51: DataView dataview = new DataView();
上面这句错误
改为
string sql="select * from (" + str + ")";
注意要指定后面的那个 t
select * from (select tablename from industry_table where induaid='"+id+"') t
--------------------------------------------------------------------------------第 1 行: ')' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: ')' 附近有语法错误。源错误:
行 47: DataSet ds = new DataSet();
行 48: SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,conn);
行 49: sqlAdapter.Fill(ds,"str");
行 50:
行 51: DataView dataview = new DataView();
id=id.Substring(0,2);
string str="select tablename from industry_table where induaid='"+id+"'";
string sql="select * from '(" + str + ")'";
改成
string id=Request.QueryString["id"].ToString();
id=id.Substring(0,2);
string str="select tablename from industry_table where induaid="+id;
string sql="select * from " + str;
string id=Request.QueryString["id"].ToString();
id=id.Substring(0,2);
string str="select tablename from industry_table where induaid="+id;
string sql="select * from (" + str + ")";
先找到SQL语句,放到查询分析器里面执行,看一下哪儿错.在C#后台代码*.cs里面检查SQL语句是否正确,能看晕掉!
改成
sqlAdapter.Fill(ds,str);
induaid='"+id+"'"
改成
induaid="+id+"";
有问题的,你到查询分析器里运行一下,tablename是列名吗?
string str="select tablename from industry_table where induaid='"+id+"'";
结果是一个单列集合
而string sql="select * from '(" + str + ")'";这里;的str需要是一个表,虽然在C#里都是字符串,但是传到SQL server中就不同了,所以还是单个查,查出结果后在手动组成新字符串,然后再放进去查