小弟请各位大虾帮帮忙,我的问题是:如何在数据库(比如Exam)中检测是否存在某一个表(比如score),,明天就要教上去了,挺急的.
解决方案 »
- 抢火车票软件~~~~~
- 点了个查询按钮,怎么页面所有的文本框都初始化了?
- gridview 导出excel 内容只有<div ></div>
- 刚面试回来...马上把题贴出来,大家看看....
- 100分求DataSet的问题?
- 快疯了:DataGrid绑定的数据居然显示不出来!
- 关于freetextbox问题,急急急!!!
- 如何在datagird中加入一个单选按钮!!!
- 求判断全角半角的函数
- 为什么我用vs.net新建asp.net应用程序出错?无法创建web项目,object not found?
- gridview嵌套checkbox的问题
- javascript 读取 datagrid 的问题
select count(*) from sysobjects where name='Exam'大于0就说明有。
comm.text = "select count(*) from sysobjects where name='Exam'";comm.connection = 你的连接;bool exists = convert.toboolean(comm.executescarlar());
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不一定适用
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();
}
判断表是否存在?
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'
print('存在');
else
print('不存在');
和
oracle
我都给你了阿难道还不行??
{
sqlcommand comm = new sqlcommand();
comm.text = "select * from Exam"; comm.connection = 你的连接; bool exists = convert.toboolean(comm.executescarlar());
}
catch
{
Respons.Write("数据库没有这个表");
}