小弟刚学VB,学着做了一个数据库维护的小程序,可是每次我运行程序到保存那步时,就提示参数类型不正确,或在不可接受的范围内,或与其他参数冲突,高手们来帮帮我啊,以下是我的源代码:
Public rs As New ADODB.Recordset
Public blnAdd As Boolean
Public i As Integer
Sub view_data()
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Text1.UBound
Text1(i) = DataGrid1.Columns(i + 1).Text
Next i
End If
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
view_data
End Sub
Private Sub Form_Load()
tlbState Toolbar1, False
view_data
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sql = ""
End SubPrivate Sub Text1_GotFocus(Index As Integer)
Text1(Index).BackColor = &HFFFF00
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index))
End Sub
Private Sub Text1_LostFocus(Index As Integer)
Text1(Index).BackColor = &H80000005
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "add"
blnAdd = True
tlbState Toolbar1, True
For i = 0 To Text1.UBound
Text1(i) = ""
Text1(i).Locked = False
Next i
Case "modify"
If Adodc1.Recordset.RecordCount > 0 Then
blnAdd = False
tlbState Toolbar1, True
For i = 0 To Text1.UBound
Text1(i).Locked = False
Next i
view_data
Else
MsgBox "系统没有要修改的数据!", , "提示"
End If
Case "delete"
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Else
MsgBox "系统没有要删除的数据!", , "提示"
End If
Case "save"
If Text1(3).Text = "" Then
MsgBox "系统不允许车型型号为空!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(7).Text) = False Then
MsgBox "请在限值1中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(8).Text) = False Then
MsgBox "请在限值2中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(10).Text) = False Then
MsgBox "请在最大净功率一栏中输入数字!", , "提示"
Exit Sub
End If
On Error GoTo saveerr
If blnAdd = True Then
rs.Open "select * from ModalStore where M_modal='" & Text1(3).Text & "'", con, adOpenKeyset
If rs.RecordCount > 0 Then
MsgBox "此车型已存在!", "提示"
Else
Dim sql As String
sql = "insert into ModalStore (M_standard,M_cartype,M_seq,M_modal,M_name,M_engineno,M_enginemf,M_appvalue,M_factvalue,M_manufacturer,M_maxpower)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + Text1(2).Text + "','" + Text1(3).Text + "','" + Text1(4).Text + "','" + Text1(5).Text + "','" + Text1(6).Text + "'," + Text1(7).Text + "," + Text1(8).Text + ",'" + Text1(9).Text + "'," + Text1(10).Text + ")"
Debug.Print sql
con.Execute ("insert into ModalStore (M_standard,M_cartype,M_seq,M_modal,M_name,M_engineno,M_enginemf,M_appvalue,M_factvalue,M_manufacturer,M_maxpower)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + Text1(2).Text + "','" + Text1(3).Text + "','" + Text1(4).Text + "','" + Text1(5).Text + "','" + Text1(6).Text + "'," + Text1(7).Text + "," + Text1(8).Text + ",'" + Text1(9).Text + "'," + Text1(10).Text + ")")
Adodc1.Refresh
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
rs.Close
Else
rs.Open "select * from ModalStore where M_modal='" + Text1(3).Text + "'", con, adOpenKeyset
If rs.RecordCount > 0 And DataGrid1.Columns(1) Then
MsgBox "此记录已存在!", "提示"
Else
con.Execute ("update ModalStore set M_standard='" + Text1(0).Text + "',M_cartype='" + Text1(1).Text + "',M_seq='" + Text1(2).Text + "',M_modal='" + Text1(3).Text + "',M_name='" + Text1(4).Text + "',M_engineno='" + Text1(5).Text + "',M_enginemf='" + Text1(6).Text + "',M_appvalue=" + Text1(7).Text + ",M_factvalue=" + Text1(8).Text + ",M_manufacturer='" + Text1(9).Text + "',M_maxpower=" + Text1(10).Text + "")
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
Adodc1.Refresh
rs.Close
End If
Exit Sub
saveerr:
MsgBox Err.Description
Case "cancel"
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
view_data
Case "close"
Unload Me
End Select
End Sub
Public rs As New ADODB.Recordset
Public blnAdd As Boolean
Public i As Integer
Sub view_data()
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Text1.UBound
Text1(i) = DataGrid1.Columns(i + 1).Text
Next i
End If
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
view_data
End Sub
Private Sub Form_Load()
tlbState Toolbar1, False
view_data
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sql = ""
End SubPrivate Sub Text1_GotFocus(Index As Integer)
Text1(Index).BackColor = &HFFFF00
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index))
End Sub
Private Sub Text1_LostFocus(Index As Integer)
Text1(Index).BackColor = &H80000005
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "add"
blnAdd = True
tlbState Toolbar1, True
For i = 0 To Text1.UBound
Text1(i) = ""
Text1(i).Locked = False
Next i
Case "modify"
If Adodc1.Recordset.RecordCount > 0 Then
blnAdd = False
tlbState Toolbar1, True
For i = 0 To Text1.UBound
Text1(i).Locked = False
Next i
view_data
Else
MsgBox "系统没有要修改的数据!", , "提示"
End If
Case "delete"
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Else
MsgBox "系统没有要删除的数据!", , "提示"
End If
Case "save"
If Text1(3).Text = "" Then
MsgBox "系统不允许车型型号为空!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(7).Text) = False Then
MsgBox "请在限值1中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(8).Text) = False Then
MsgBox "请在限值2中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(10).Text) = False Then
MsgBox "请在最大净功率一栏中输入数字!", , "提示"
Exit Sub
End If
On Error GoTo saveerr
If blnAdd = True Then
rs.Open "select * from ModalStore where M_modal='" & Text1(3).Text & "'", con, adOpenKeyset
If rs.RecordCount > 0 Then
MsgBox "此车型已存在!", "提示"
Else
Dim sql As String
sql = "insert into ModalStore (M_standard,M_cartype,M_seq,M_modal,M_name,M_engineno,M_enginemf,M_appvalue,M_factvalue,M_manufacturer,M_maxpower)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + Text1(2).Text + "','" + Text1(3).Text + "','" + Text1(4).Text + "','" + Text1(5).Text + "','" + Text1(6).Text + "'," + Text1(7).Text + "," + Text1(8).Text + ",'" + Text1(9).Text + "'," + Text1(10).Text + ")"
Debug.Print sql
con.Execute ("insert into ModalStore (M_standard,M_cartype,M_seq,M_modal,M_name,M_engineno,M_enginemf,M_appvalue,M_factvalue,M_manufacturer,M_maxpower)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + Text1(2).Text + "','" + Text1(3).Text + "','" + Text1(4).Text + "','" + Text1(5).Text + "','" + Text1(6).Text + "'," + Text1(7).Text + "," + Text1(8).Text + ",'" + Text1(9).Text + "'," + Text1(10).Text + ")")
Adodc1.Refresh
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
rs.Close
Else
rs.Open "select * from ModalStore where M_modal='" + Text1(3).Text + "'", con, adOpenKeyset
If rs.RecordCount > 0 And DataGrid1.Columns(1) Then
MsgBox "此记录已存在!", "提示"
Else
con.Execute ("update ModalStore set M_standard='" + Text1(0).Text + "',M_cartype='" + Text1(1).Text + "',M_seq='" + Text1(2).Text + "',M_modal='" + Text1(3).Text + "',M_name='" + Text1(4).Text + "',M_engineno='" + Text1(5).Text + "',M_enginemf='" + Text1(6).Text + "',M_appvalue=" + Text1(7).Text + ",M_factvalue=" + Text1(8).Text + ",M_manufacturer='" + Text1(9).Text + "',M_maxpower=" + Text1(10).Text + "")
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
Adodc1.Refresh
rs.Close
End If
Exit Sub
saveerr:
MsgBox Err.Description
Case "cancel"
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
view_data
Case "close"
Unload Me
End Select
End Sub
Public rs As New ADODB.Recordset
Public blnAdd As Boolean
Public i As Integer
Sub view_data()
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Text1.UBound
Text1(i) = DataGrid1.Columns(i + 1).Text
Next i
End If
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
view_data
End Sub
Private Sub Form_Load()
tlbState Toolbar1, False
view_data
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sql = ""
End SubPrivate Sub Text1_GotFocus(Index As Integer)
Text1(Index).BackColor = &HFFFF00
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index))
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And Index < 11 Then Text1(Index + 1).SetFocus
If KeyCode = vbKeyReturn And Index = 10 Then Text1(10).SetFocus
End Sub
Private Sub Text1_LostFocus(Index As Integer)
Text1(Index).BackColor = &H80000005
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "add"
blnAdd = True
tlbState Toolbar1, True
For i = 1 To Text1.UBound
Text1(i) = ""
Text1(i).Locked = False
Next i
Case "modify"
If Adodc1.Recordset.RecordCount > 0 Then
blnAdd = False
tlbState Toolbar1, True
For i = 1 To Text1.UBound
Text1(i).Locked = False
Next i
view_data
Else
MsgBox "系统没有要修改的数据!", , "提示"
End If
Case "delete"
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Else
MsgBox "系统没有要删除的数据!", , "提示"
End If
Case "save"
If Text1(3).Text = "" Then
MsgBox "系统不允许车型型号为空!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(7)) = False Then
MsgBox "请在限值1中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(8)) = False Then
MsgBox "请在限值2中输入数字!", , "提示"
Exit Sub
End If
If IsNumeric(Text1(10)) = False Then
MsgBox "请在最大净功率一栏中输入数字!", , "提示"
Exit Sub
End If
On Error GoTo saveerr
If blnAdd = True Then
rs.Open "select * from ModalStore where M_modal='" & Text1(3) & "'", con, adOpenKeyset
If rs.RecordCount > 0 Then
MsgBox "此车型已存在!", "提示"
Else
con.Execute ("insert into ModalStore(M_standard,M_cartype,M_seq,M_modal,M_name,M_engineno,M_enginemf,M_appvalue,M_factvalue,M_manufacturer,M_maxpower)values('" & Text1(0) & "','" & Text1(1) & "','" & Text1(2) & "','" & Text1(3) & "','" & Text1(4) & "','" & Text1(5) & "','" & Text1(6) & "'," & CDec(Text1(7)) & "," & CDec(Text1(8)) & ",'" & Text1(9) & "'," & CDec(Text1(10)) & ") ")
Adodc1.Refresh
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
rs.Close
Else
rs.Open "select * from ModalStore where M_modal='" & Text1(3) & "'", con, adOpenKeyset
If rs.RecordCount > 0 And DataGrid1.Columns(1) Then
MsgBox "此记录已存在!", "提示"
Else
con.Execute ("update ModalStore set M_standard='" & Text1(0) & "',M_cartype='" & Text1(1) & "',M_seq='" & Text1(2) & "',M_modal='" & Text1(3) & "',M_name='" & Text1(4) & "',M_engineno='" & Text1(5) & "',M_enginemf='" & Text1(6) & "',M_appvalue=" & CDec(Text1(7)) & ",M_factvalue=" & CDec(Text1(8)) & ",M_manufacturer='" & Text1(9) & "',M_maxpower=" & CDec(Text1(10)) & "")
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
End If
Adodc1.Refresh
rs.Close
End If
Exit Sub
saveerr:
MsgBox Err.Description
Case "cancel"
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
view_data
Case "close"
Unload Me
End Select
End Sub
具体错误是哪一句?
这句有错
2,确认M_modal字段的数据类型
3,rs.Open "select * from ModalStore where M_modal='" & Text1(3) & "'", con, adOpenKeyset,adlockreadonly