在sql中写了一个T-Sql脚本,执行后建库,建表,建视图,存储过程,在sql中运行正常 现在想要在C#程序中执行
sb=newStringBuilder();sb.Append("usemaster");sb.Append("ifexists(select*fromsysdataba...
sb = new StringBuilder();
sb.Append("use master");
sb.Append(" if exists(select * from sysdatabases where name='RemPacs_1')");
sb.Append(" drop database RemPacs_1");
sb.Append(" create database RemPacs_1");
sb.Append(" use RemPacs_1");
sb.Append(" if exists(select * from sysobjects where name='GLB_AgeUnit')");
sb.Append(" drop table GLB_AgeUnit");
sb.Append(" create table GLB_AgeUnit");
sb.Append(" (");
sb.Append(" AgeUnitID int not null primary key,");
sb.Append(" [Name] nvarchar(4) not null,");
sb.Append(" DisplayNo int not null");
sb.Append(" )");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(1,'岁',1)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(2,'月',2)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(3,'周',3)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(4,'天',4)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(5,'时',5)");
SqlCommand cmd = new SqlCommand(sb.ToString(), GetConnection());
int i = cmd.ExecuteNonQuery();
我这样写的 ,但是建不了 展开
sb.Append("use master");
sb.Append(" if exists(select * from sysdatabases where name='RemPacs_1')");
sb.Append(" drop database RemPacs_1");
sb.Append(" create database RemPacs_1");
sb.Append(" use RemPacs_1");
sb.Append(" if exists(select * from sysobjects where name='GLB_AgeUnit')");
sb.Append(" drop table GLB_AgeUnit");
sb.Append(" create table GLB_AgeUnit");
sb.Append(" (");
sb.Append(" AgeUnitID int not null primary key,");
sb.Append(" [Name] nvarchar(4) not null,");
sb.Append(" DisplayNo int not null");
sb.Append(" )");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(1,'岁',1)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(2,'月',2)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(3,'周',3)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(4,'天',4)");
sb.Append(" insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(5,'时',5)");
SqlCommand cmd = new SqlCommand(sb.ToString(), GetConnection());
int i = cmd.ExecuteNonQuery();
我这样写的 ,但是建不了 展开
5个回答
展开全部
sb = new StringBuilder();
sb.Append(@"use master
if exists(select * from sysdatabases where name='RemPacs_1')
drop database RemPacs_1
create database RemPacs_1
use RemPacs_1
if exists(select * from sysobjects where name='GLB_AgeUnit')
drop table GLB_AgeUnit
create table GLB_AgeUnit
(
AgeUnitID int not null primary key,
[Name] nvarchar(4) not null,
DisplayNo int not null
)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(1,'岁',1)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(2,'月',2)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(3,'周',3)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(4,'天',4)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(5,'时',5)");
SqlCommand cmd = new SqlCommand(sb.ToString(), GetConnection());
int i = cmd.ExecuteNonQuery();
sb.Append(@"use master
if exists(select * from sysdatabases where name='RemPacs_1')
drop database RemPacs_1
create database RemPacs_1
use RemPacs_1
if exists(select * from sysobjects where name='GLB_AgeUnit')
drop table GLB_AgeUnit
create table GLB_AgeUnit
(
AgeUnitID int not null primary key,
[Name] nvarchar(4) not null,
DisplayNo int not null
)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(1,'岁',1)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(2,'月',2)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(3,'周',3)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(4,'天',4)
insert into GLB_AgeUnit (AgeUnitID,[Name],DisplayNo) values(5,'时',5)");
SqlCommand cmd = new SqlCommand(sb.ToString(), GetConnection());
int i = cmd.ExecuteNonQuery();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
l路径 调用。。(传参)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调试一下看看在DBS里查看一下哪里有没有报错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把多语句一起传过去执行,在每个完整的SQL语句后面加上;
否则识别不了
否则识别不了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我给你写了个例子 发给你消息了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询