Insert Into 语句出错?

sluckywhh 2004-08-27 09:06:24
问题是这样的:我在做一个三层结构的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
...全文
139 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyg0 2004-08-27
  • 打赏
  • 举报
回复
乱七七
数据库acess用
字符型: '"& 变量名 &"'
日期型变量用 #"& 变量名 &"#

'数值型变量用:"& 变量名 & "

sql_server
全是'"& 变量名 &"'
不过都要注意,日期类型在插入前一定要判断是日期的数据
yijiansong 2004-08-27
  • 打赏
  • 举报
回复
学习
sluckywhh 2004-08-27
  • 打赏
  • 举报
回复
谢谢leftie和of123兄。
of123 2004-08-27
  • 打赏
  • 举报
回复

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 & Format(Me.dIntime, "yyyy-mm-dd") & "#,#" & Format(Me.dOuttime, "yyyy-mm-dd") & "#,'" & Me.cAcc_Station & "','"
strSQL = strSQL & Me.iYear & "','" & Me.cRunOption & "'," & Me.bDisp & ")"
饮水需思源 2004-08-27
  • 打赏
  • 举报
回复
strSQL = "Insert Into AccountLog (cAcc_ID,cAcc_Sub_ID,cUser_ID,dIntime,dOuttime,cAcc_Station,iYear,cRunOption,bDisp) Values ('" & Me.cAcc_ID & "','" & Me.cAcc_Sub_ID & "','" & Me.cUser_ID & "','" & Me.dIntime & "','" & Me.dOuttime & "','" & Me.cAcc_Station & "'," & Me.iYear & ",'" & Me.cRunOption & "'," & Me.bDisp & ")"

'字符型与日期型变量用: '"& 变量名 &"'
'数值型变量用:"& 变量名 & "

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧