小弟请各位大虾帮帮忙,我的问题是:如何在数据库(比如Exam)中检测是否存在某一个表(比如score),,明天就要教上去了,挺急的.

解决方案 »

  1.   

    是什么数据库?SQL Server吗?
    select count(*) from sysobjects where name='Exam'大于0就说明有。
      

  2.   

    sqlcommand comm = new sqlcommand();
    comm.text = "select count(*) from sysobjects where name='Exam'";comm.connection = 你的连接;bool exists = convert.toboolean(comm.executescarlar());
      

  3.   

    oracommand comm = new oracommand();
    comm.text = "select count(*) from sys.all_all_tables where tablespace = '你的表控件的名字' and name='Exam'";//也可以将tablespace换成owner(一般情况下,我喜欢把表空间的名字定得跟用户名一样)comm.connection = 你的连接;bool exists = convert.toboolean(comm.executescarlar());
    以上代码仅使用与MS给的那个ORacle dataprovider,对于odp.net不一定适用
      

  4.   

    我写的程序如下,目的的就是如果exam数据库中不存在score表就创建该表:
    SqlConnection   con1=new SqlConnection("Data Source=MEIJIN;Initial Catalog=exam;User ID=sa;PWD=sa;");
    string sel ="select count(*) from sysobjects where name='"+getzhy+"'";
    SqlDataAdapter cmd1=new SqlDataAdapter();
    cmd1=new SqlDataAdapter(sel,con1);
    con1.Open();
    DataSet ds1=new DataSet();
    int count1=cmd1.Fill(ds1,"found1");
    con1.Close();
    if(count1<=0)
    {
    创建课程试题数据库;
    string creat="create table "+getzhy+"(tmno int primary key ,zhy char(30) not null,tmtype char(20) not null,tmcontent char(500) not null,tmanswer char(1000) not null)";
    SqlCommand cmd=new SqlCommand(creat,con1);
    con1.Open();
    cmd.ExecuteNonQuery();
    con1.Close();
    }
      

  5.   

    更正oracle的sql语句comm.text = "select count(*) from sys.all_all_tables where tablespace_name = '你的表控件的名字' and table_name='Exam'";
      

  6.   

    刚才没说清楚,我用的是SQL数据库啊
      

  7.   

    select count(*) from sysobjects where xtype='u'
      

  8.   


    判断表是否存在?
    if not exists(select * from sysobjects where Name='表名') 
       begin
     CREATE TABLE [dbo].[Doctors] (
     [MemberID] [nvarchar] (20)  NOT NULL ,
     [DoctorID] [nvarchar] (20)  NOT NULL ,
     [DoctorName] [nvarchar] (20)  NULL ,
     [
     )
       end
    else
      print 'This Table Is Exists'
      

  9.   

    用c#写可以写成select count(*) from sysobjects where name='Exam'楼上已经说出了答案!
      

  10.   

    select count(*) from sysobjects where name='Exam'不是用这个吗?怎么还不能解决吗?
      

  11.   

    if exists(select * from sysobjects where Name='score'  and xtype='u')
    print('存在');
    else
    print('不存在');
      

  12.   

    sql server

    oracle
    我都给你了阿难道还不行??
      

  13.   

    try
    {
      sqlcommand comm = new sqlcommand();
      comm.text = "select * from Exam";   comm.connection = 你的连接;   bool exists = convert.toboolean(comm.executescarlar());
    }
    catch
    {
       Respons.Write("数据库没有这个表");
    }
      

  14.   

    select * from sysobjects where Name='score'  and xtype='u'