我用vb做程序,是按照书上的实例做的,书上的代码可以正常运行,而我自己按照书上的重新做了一遍却出现“类型不匹配”的错误,连接的是同一个数据库,出错的代码是:
Public OriTypeId As String '修改状态时,房间类型记录中原有的类型编号。这是此记录的标识
Private Sub Cmd_OK_Click()
'检查用户录入的数据是否完全有效
'客房类型、房间数量、床位数量是必须输入的
If Trim(txtRtype) = "" Then
MsgBox "请输入客房类型"
txtRtype.SetFocus
Exit Sub
End If
If Trim(txtRnum) = "" Then
MsgBox "请输入房间数量"
txtRnum.SetFocus
Exit Sub
End If
If Trim(txtBnum) = "" Then
MsgBox "请输入床位数量"
txtBnum.SetFocus
Exit Sub
End If
'把用户录入的数据赋值到MyRoomType对象中,并保存到数据库
With MyRoomType
.TypeName = MakeStr(txtRtype.Text) '客房类型
.RoomNum = Val(txtRnum) '房间数量
.Bednum = Val(txtBnum) '床位数量
If Option1.Value = True Then '空调
.AirConditioning = 1
Else
.AirConditioning = 0
End If
……
If Option9.Value = True Then '冰箱
.IceBox = 1
Else
.IceBox = 0
End If
'Modify=False表示当前为插入新数据状态;否则为修改数据状态
If Modify = False Then
'判断当前房间类型是否存在
If .In_DB(.TypeName) = True Then
MsgBox "当前房间类型已经存在"
Exit Sub
End If
.Insert
Else
If .TypeName <> OriType Then
'判断当前客户是否存在
If .In_DB(.TypeName) = True Then
MsgBox "当前房间类型已经存在"
Exit Sub
End If
End If
.Update (OriTypeId)…………出错
End If
End With
Unload Me
End Sub
可以插入,但是不能修改,请高人指点一下,谢谢!!
Public OriTypeId As String '修改状态时,房间类型记录中原有的类型编号。这是此记录的标识
Private Sub Cmd_OK_Click()
'检查用户录入的数据是否完全有效
'客房类型、房间数量、床位数量是必须输入的
If Trim(txtRtype) = "" Then
MsgBox "请输入客房类型"
txtRtype.SetFocus
Exit Sub
End If
If Trim(txtRnum) = "" Then
MsgBox "请输入房间数量"
txtRnum.SetFocus
Exit Sub
End If
If Trim(txtBnum) = "" Then
MsgBox "请输入床位数量"
txtBnum.SetFocus
Exit Sub
End If
'把用户录入的数据赋值到MyRoomType对象中,并保存到数据库
With MyRoomType
.TypeName = MakeStr(txtRtype.Text) '客房类型
.RoomNum = Val(txtRnum) '房间数量
.Bednum = Val(txtBnum) '床位数量
If Option1.Value = True Then '空调
.AirConditioning = 1
Else
.AirConditioning = 0
End If
……
If Option9.Value = True Then '冰箱
.IceBox = 1
Else
.IceBox = 0
End If
'Modify=False表示当前为插入新数据状态;否则为修改数据状态
If Modify = False Then
'判断当前房间类型是否存在
If .In_DB(.TypeName) = True Then
MsgBox "当前房间类型已经存在"
Exit Sub
End If
.Insert
Else
If .TypeName <> OriType Then
'判断当前客户是否存在
If .In_DB(.TypeName) = True Then
MsgBox "当前房间类型已经存在"
Exit Sub
End If
End If
.Update (OriTypeId)…………出错
End If
End With
Unload Me
End Sub
可以插入,但是不能修改,请高人指点一下,谢谢!!
TypeId int 4 0
TypeName varchar 100 0
RoomNum int 4 1
Bednum int 4 1
AirConditioning int 4 1
Tel int 4 1
Tv int 4 1
Toilet int 4 1
IceBox int 4 1这是添加和修改客房类型信息,可以添加和修改客房类型、房间数量、床位数量和是否有配套设施,添加的时候没问题,但是修改的时候就会出现“类型不匹配”
Public Sub Update(ByVal TmpId As Long)
SqlStmt = "UPDATE RoomType SET TypeName='" + Trim(TypeName) _
+ "',RoomNum=" + Trim(RoomNum) + ", Bednum=" _
+ Trim(Bednum) + ", AirConditioning=" + Trim(AirConditioning) _
+ ", Tel=" + Trim(Tel) + ", Tv=" + Trim(Tv) + ", Toilet=" _
+ Trim(Toilet) + ", IceBox=" + Trim(IceBox) + " Where TypeId = " _
+ Trim(Str(TmpId))
SQLExt (SqlStmt)
End Sub是这个吗??
SqlStmt = "UPDATE RoomType SET TypeName='" & Trim(TypeName) _
& "',RoomNum=" & Trim(RoomNum) & ", Bednum=" _
& Trim(Bednum) & ", AirConditioning=" & Trim(AirConditioning) _
& ", Tel=" & Trim(Tel) & ", Tv=" & Trim(Tv) & ", Toilet=" _
& Trim(Toilet) & ", IceBox=" & Trim(IceBox) & " Where TypeId = " _
& Trim(TmpId)
SQLExt (SqlStmt)
End Sub或 .Update (Val(OriTypeId))…………出错