Insert Into 语句出错?

sluckywhh sluckywhh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题是这样的:我在做一个三层结构的C/S,数据库中的表用类封装后在Client端用其中的AddNew添加新记录却出现错误。具体情况如下:
Option Explicit
Private mAccID As String
Private mAccSubID As Integer
Private mUserID As String
Private mIntime As Date
Private mOuttime As Date
Private mAccStation As String
Private mYear As String
Private mRunOption As String
Private mDisp As Integer

Private bInit As Boolean

Public Property Get cAcc_ID() As String
cAcc_ID = mAccID
End Property

Public Property Let cAcc_ID(ByVal NewVal As String)
NewVal = Trim(NewVal)
If NewVal = "0000" Then
mAccID = NewVal
Exit Property
Else
If Len(Trim(NewVal)) >= 4 Then
NewVal = Left$(NewVal, 4)
End If
If IsNumeric(NewVal) = False Then
Exit Property
End If
Dim lCol As Long
If Not oColAcc Is Nothing Then
For lCol = 1 To oColAcc.Count
If NewVal = oColAcc(lCol) Then
mAccID = NewVal
Exit For
End If
Next
End If
End If
End Property

Public Property Get cAcc_Sub_ID() As Integer
cAcc_Sub_ID = mAccSubID
End Property

Public Property Let cAcc_Sub_ID(ByVal NewVal As Integer)
mAccSubID = NewVal
End Property

Public Property Get cUser_ID() As String
cUser_ID = mUserID
End Property

Public Property Let cUser_ID(ByVal NewVal As String)
NewVal = Trim(NewVal)
If Ucase(NewVal) = "SA" Then
mUserID = NewVal
Exit Property
Else
If Len(NewVal) >= 12 Then
NewVal = Left$(NewVal, 12)
End If
Dim lCol As Long
If Not oColMas Is Nothing Then
For lCol = 1 To oColMas.Count
If NewVal = oColMas(lCol) Then
mUserID = NewVal
End If
Next
End If
End If
End Property

Public Property Get dIntime() As Date
dIntime = mIntime
End Property

Public Property Let dIntime(ByVal NewVal As Date)
mIntime = NewVal
End Property

Public Property Get dOuttime() As Date
dOuttime = mOuttime
End Property

Public Property Let dOuttime(ByVal NewVal As Date)
mOuttime = NewVal
End Property

Public Property Get cAcc_Station() As String
cAcc_Station = mAccStation
End Property

Public Property Let cAcc_Station(ByVal NewVal As String)
NewVal = Trim(NewVal)
If Len(NewVal) >= 255 Then
NewVal = Left$(NewVal, 255)
End If
mAccStation = NewVal
End Property

Public Property Get iYear() As String
iYear = mYear
End Property

Public Property Let iYear(ByVal NewVal As String)
NewVal = Trim(NewVal)
If Len(NewVal) >= 4 Then
NewVal = Left$(NewVal, 4)
End If
If IsNumeric(NewVal) = False Then
Exit Property
End If
If Val(NewVal) < 1900 Or Val(NewVal) > 2100 Then
Exit Property
End If
mYear = NewVal
End Property

Public Property Get cRunOption() As String
cRunOption = mRunOption
End Property

Public Property Let cRunOption(ByVal NewVal As String)
NewVal = Trim(NewVal)
If Len(NewVal) >= 1000 Then
NewVal = Left$(NewVal, 1000)
End If
mRunOption = NewVal
End Property

Public Property Get bDisp() As Integer
bDisp = mDisp
End Property

Public Property Let bDisp(ByVal NewVal As Integer)
If NewVal >= 1 Then
mDisp = 1
Else
mDisp = 0
End If
End Property

Public Function AddNew() As Boolean
Dim strSQL As String
If bInit Then
Select Case True
Case Trim(mAccID) = ""
GoTo errAdd
Case Trim(mAccStation) = ""
GoTo errAdd
Case Trim(mYear) = ""
GoTo errAdd
Case Trim(mRunOption) = ""
GoTo errAdd
Case Else
oADOConnect.BeginTrans
strSQL = "Insert Into AccountLog (cAcc_ID,cAcc_Sub_ID,cUser_ID,dIntime,dOuttime,cAcc_Station,iYear,cRunOption,bDisp) Values ("
strSQL = strSQL & Me.cAcc_ID & "," & Me.cAcc_Sub_ID & "," & Me.cUser_ID & ","
strSQL = strSQL & Me.dIntime & "," & Me.dOuttime & "," & Me.cAcc_Station & ","
strSQL = strSQL & Me.iYear & "," & Me.cRunOption & "," & Me.bDisp & ")"

oADOConnect.Execute strSQL
oADOConnect.CommitTrans

AddNew = (Err.Number = 0)
InitClass

End Select
Else
GoTo errAdd
End If

Exit Function

errAdd:
AddNew = False
Exit Function
End Function

Private Sub Class_Initialize()
If oADOConnect Is Nothing Then
bInit = False
Else
bInit = True
InitClass
End If
End Sub

Private Sub InitClass()
mAccID = ""
mAccSubID = 0
mUserID = ""
mIntime = Now()
mOuttime = Now()
mAccStation = ""
mYear = CStr(Year(Now()))
mRunOption = ""
mDisp = 1
End Sub
...全文

相关推荐

在SQL Server中生成INSERT语句

在SQL Server中生成INSERT..VALUES语句的存储过程。

weixin_38530202

正确使用MySQL INSERT INTO语句

以下的文章主要介绍的是MySQL INSERT INTO语句的实际用法以及MySQL INSERT INTO语句中的相关语句的介绍,MySQL INSERT INTO语句在实际应用中是经常使用到的语句,所以对其相关的内容还是多多掌握为好。 INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES (expression,...),(...),... MySQLINSERT INTO SELECT语句: INSERT [LOW_PRIORITY | DELAYED] [IGNORE]

weixin_38586200

MYSQL SELECT INTO 和 INSERT INTO SELECT

关于MySQL中“SELECT INTO”和“INSERT INTO SELECT”两种语法的使用与说明。

oldfour619

INSERT INTO SELECT语句与SELECT INTO FROM语句的一些区别

1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,…) select value1,value2,… from Table1 要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下: INSERT INTO SELECT语句复制表数据 代码如下: –1.创建测试表 create TABLE Table1 ( a varchar(10), b varchar(10), c varchar(10), CONSTRAINT [PK_Table1] P

weixin_38529436

SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解(SQL数据库和Oracle数据库的区别)

1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,…) select value1,value2,… from Table1 或者:Insert into Table2 select * from Table1 注意:(1)要求目标表Table2必须存在,并且字段field,field2…也必须存在 (2)注意Table2的主键约束,如果Table2有主键而且不为空,则 field1, field2…中必须包括主键 (3)注意语法,不要加values,和插入一条数据的sql混了,不要写成: Insert into Tab

weixin_38673237
评论 5
收藏 已收藏
分享
返回顶部