我用c#做了个界面,想在listbox1中显示所有数据库中的表的名称,然后再选择listbox1中的某个表名时,自动在listbox2中显示该表中的所有字段名,第一步已经实现,代码如下: 
string conStr = "Server=CX\\OBCINSTANCE2;" + "Trusted_Connection=yes;" + "database=music system"; 
            SqlConnection con = new SqlConnection(conStr); 
            con.Open(); 
            string sqlStr = "select * from tab"; 
            SqlCommand cmd = new SqlCommand(sqlStr, con); 
            SqlDataReader dr = cmd.ExecuteReader(); 
            while(dr.Read()) 
            { 
                this.listBox1.Items.Add(dr[0]); 
            } 
第二步中的代码如下: 
string conStr = "Server=CX\\OBCINSTANCE2;" + "Trusted_Connection=yes;" + "database=music system"; 
            SqlConnection con = new SqlConnection(conStr); 
            con.Open(); 
            string sqlStr = "select * from "+this.listBox1.SelectedItem; 
            SqlCommand cmd = new SqlCommand(sqlStr, con); 
            SqlDataReader dr = cmd.ExecuteReader(); 
            while (dr.Read()) 
            { 
                this.listBox2.Items.Add(dr[0]); 
            } 
第二步发生了异常:ora-00923  from  
请问各位大侠应该如何解决这个异常啊,高分求教!!

解决方案 »

  1.   

    ORA-00923 FROM keyword not found where expectedCause: In a SELECT or REVOKE statement, the keyword FROM was either missing, misplaced, or misspelled. The keyword FROM must follow the last selected item in a SELECT statement or the privileges in a REVOKE statement.Action: Correct the syntax. Insert the keyword FROM where appropriate. The SELECT list itself also may be in error. If quotation s were used in an alias, check that double quotation s enclose the alias. Also, check to see if a reserved word was used as an alias._______________________________________________debug一下
    运行到        string sqlStr = "select * from "+this.listBox1.SelectedItem;  时
    this.listBox1.SelectedItem 有没有值?
    错误提示,from 后的表有问题!
      

  2.   

    this.listBox1.SelectedItem 是不是没有选出数据来啊.
    加个:System.out.print(sqlStr); 看看.
      

  3.   

    我没用过c#,用过asp.net,
    this.listBox1.SelectedItem这个室ITEM对象,
    应该还有this.listBox1.SelectedItem.text和this.listBox1.SelectedItem.value属性吧,
    用其中任意一个,应该就可以了.
      

  4.   


    做过C#开发,SelectedItem.text通常用来显示,SelectedItem.value用来后台传值。this.listBox1.SelectedItem有很多属性,使用textstring sqlStr = "select * from "+this.listBox1.SelectedItem.text; 
      

  5.   

    string sqlStr = "select * from "+this.listBox1.SelectedItem.ToString
    就可以了,你的SQL是个字符串,ListBox1.SelectedItem非STRING类型。
    建议:以后遇这类问题去C#版块问,我认为懂C#的基本都懂数据库,但懂数据库的不一定懂C#
      

  6.   

    select Item 是对像  需要ToString();
    呵呵  留在这个版块了  有点意思可以设个断点看一下呀  选中要调试的代码,右击选择快速监视  结果都在这里面另外就是不要把页面层的控件都传到数据访问层   只返回一个数据集就好 例如 DATATABLE   DATASET等