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();
 

解决方案 »

  1.   

    string sql="select * from '(" + str + ")'";
    上面这句错误
    改为
    string sql="select * from (" + str + ")";
      

  2.   

    其实你想表达这个意思,你把它写在一起就可以了
    注意要指定后面的那个 t
    select * from (select tablename from industry_table where induaid='"+id+"') t
      

  3.   

    “/Web”应用程序中的服务器错误。
    --------------------------------------------------------------------------------第 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();
     
      

  4.   

    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 + ")'";
    改成
    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;
      

  5.   

    错了,应该是
    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 + ")";
      

  6.   

    F9跟踪,设断点,先不执行ado.net访问数据库.
    先找到SQL语句,放到查询分析器里面执行,看一下哪儿错.在C#后台代码*.cs里面检查SQL语句是否正确,能看晕掉!
      

  7.   

    本身的SQL语法就不对,在用Select语句的时候,From部分可以用Select来做子查询来形成临时表,但不能用它作为表的参数。
      

  8.   

    先把sql语句扔到查询分析器里检查一下
      

  9.   

    对,分成两步,可能数据库不支持这样执行sql,你可以用断点把sql打出来,直接在数据库中执行,看看行不行
      

  10.   

    sqlAdapter.Fill(ds,"str");
    改成
    sqlAdapter.Fill(ds,str);
    induaid='"+id+"'"
    改成
    induaid="+id+"";
      

  11.   

    string str="select tablename from industry_table where induaid="+id;
    有问题的,你到查询分析器里运行一下,tablename是列名吗?
      

  12.   

    好象不能那样吧,因为
    string str="select tablename from industry_table where induaid='"+id+"'";
    结果是一个单列集合
    而string sql="select * from '(" + str + ")'";这里;的str需要是一个表,虽然在C#里都是字符串,但是传到SQL server中就不同了,所以还是单个查,查出结果后在手动组成新字符串,然后再放进去查
      

  13.   

    你先到查询分析器里面执行一下select * from (select tablename from industry_table where induaid="+id+")  去数据表里面找个真实的ID替换一下~