vb 数据库不能更新问题,求大神;
DimconnAsADODB.ConnectionDimrsAsADODB.RecordsetPrivateSubCommand1_Click()DimnumAsInte...
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Dim num As Integer
If Text1.text = "" Then
MsgBox "请输入0~255的有效字符"
Else
num = Val(Text1.text)
MsgBox num
rs.Open "select count(*) from 设备表 where 设备编号=" & Val(text), conn, , adCmdTable
If rs.RecordCount > 0 Then
MsgBox "该设备已存在,请重新输入!"
Text1.text = ""
Else
rs.AddNew
rs.Fields(0) = Val(Text1.text)
rs.Fields(1) = Val(Combo1.text)
rs.Update
End If
End If
Me.Visible = False
'Frm_main.Show
rs.Close
conn.Close
End Sub
Private Sub Form_Load()
Text1.text = "请输入一个0~255的数字"
Combo1.text = "0"
Combo1.AddItem "0"
Combo1.AddItem "1"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\鞠发志\新气象\气象.mdb;Persist Security Info=False"
conn.Open
'rs.Open "设备表", conn, , adCmdTable
End Sub
错误提示在rs.AddNew这一行 展开
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Dim num As Integer
If Text1.text = "" Then
MsgBox "请输入0~255的有效字符"
Else
num = Val(Text1.text)
MsgBox num
rs.Open "select count(*) from 设备表 where 设备编号=" & Val(text), conn, , adCmdTable
If rs.RecordCount > 0 Then
MsgBox "该设备已存在,请重新输入!"
Text1.text = ""
Else
rs.AddNew
rs.Fields(0) = Val(Text1.text)
rs.Fields(1) = Val(Combo1.text)
rs.Update
End If
End If
Me.Visible = False
'Frm_main.Show
rs.Close
conn.Close
End Sub
Private Sub Form_Load()
Text1.text = "请输入一个0~255的数字"
Combo1.text = "0"
Combo1.AddItem "0"
Combo1.AddItem "1"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\鞠发志\新气象\气象.mdb;Persist Security Info=False"
conn.Open
'rs.Open "设备表", conn, , adCmdTable
End Sub
错误提示在rs.AddNew这一行 展开
1个回答
展开全部
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Dim num As Integer
If Text1.text = "" Then
MsgBox "请输入0~255的有效字符"
Else
num = Val(Text1.text)
'MsgBox num
rs.Open "select * from 设备表 where 设备编号=" & num, conn, 1, 3
If Not rs.EOF Then
MsgBox "该设备已存在,请重新输入!"
Text1.text = ""
Else
rs.AddNew
rs(0) = num
rs(1) = Val(Combo1.Text)
rs.Update
End If
rs.Close
End If
Me.Visible = False
'Frm_main.Show
End Sub
Private Sub Form_Load()
Text1.Text = "请输入一个0~255的数字"
Combo1.Clear
Combo1.AddItem "0"
Combo1.AddItem "1"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\鞠发志\新气象\气象.mdb;Persist Security Info=False"
conn.Open
'rs.Open "设备表", conn, , adCmdTable
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询