SQL在查询分析器中执行不成功,在VB开发的程序中没有任何提示,想获取提示怎么做?
在查询分析器中执行以下SQL语句,【数据库中已存在表:BaseAreaAssort】
use ZHData_001
CREATE TABLE [BaseAreaAssort] (
[AssortID] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[AssortCode] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[AssortName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[AssortGrade] [int] NOT NULL ,
[AssortEnd] [bit] NOT NULL ,
[define1] [int] NULL ,
[define2] [int] NULL ,
[define3] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[define4] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[define5] [datetime] NULL ,
[define6] [numeric](18, 6) NULL ,
CONSTRAINT [PK_BaseAreaAssort] PRIMARY KEY CLUSTERED
(
[AssortID]
) ON [PRIMARY]
) ON [PRIMARY]
go
消息 2714,级别 16,状态 6,第 7 行
数据库中已存在名为 'BaseAreaAssort' 的对象。
VB开发的程序:
On Error GoTo f_Error
Dim txtsql As String
Dim gConn As New ADODB.Connection
'......此次省去连接数据库代码
txtsql = "use ZHData_001"
txtsql = txtsql + " CREATE TABLE [BaseAreaAssort] ("
txtsql = txtsql + " [AssortID] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
txtsql = txtsql + " [AssortCode] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
txtsql = txtsql + " [AssortName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
txtsql = txtsql + " [AssortGrade] [int] NOT NULL ,"
txtsql = txtsql + " [AssortEnd] [bit] NOT NULL ,"
txtsql = txtsql + " [define1] [int] NULL ,"
txtsql = txtsql + " [define2] [int] NULL ,"
txtsql = txtsql + " [define3] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,"
txtsql = txtsql + " [define4] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,"
txtsql = txtsql + " [define5] [datetime] NULL ,"
txtsql = txtsql + " [define6] [numeric](18, 6) NULL ,"
txtsql = txtsql + " CONSTRAINT [PK_BaseAreaAssort] PRIMARY KEY CLUSTERED"
txtsql = txtsql + " ("
txtsql = txtsql + " [AssortID]"
txtsql = txtsql + " ) ON [PRIMARY]"
txtsql = txtsql + " ) ON [PRIMARY]"
gConn.Execute (txtsql)
Exit Sub
f_Error:
Me.MousePointer = 0
MsgBox "错误码:" & Err.Number & Chr(13) & Err.Source & ":" & Err.Description, vbExclamation, "提示"
没有任何提示错误,为什么呀?
------解决方案--------------------建议你去vb 版块问问
------解决方案--------------------在VB中没有获取异常吧!还是说你运行完VB的程序后,又在数据库里运行,那样子是VB代码建了这个表,SQL代码创建的时候肯定提示有存在。
------解决方案--------------------脚本的东西还是不建议放在程序里执行
------解决方案--------------------加个if exists 吧
------解决方案--------------------
去掉txtsql = "use ZHData_001"
你大概中了VB陷阱
gConn.Execute (txtsql)
改成
Call gConn.Execute (txtsql)
------解决方案--------------------
消息 2714,级别 16,状态 6,第 7 行
数据库中已存在名为 'BaseAreaAssort' 的对象。
------------------
创建前先判断BaseAreaAssort是否存在,如果存在先删除之,然后再创建.
if object_id('ZHData_001..BaseAreaAssort') is not null