无法向数据库添加新记录
代码如下:Private Sub Command1_Click()
On Error GoTo adderr
Dim con As New ADODB.Connection
Dim sql As String
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" _
Or Text7.Text = "" Or Text8.Text = "" Or Text9.Text = "" Or Text10.Text = "" Or Text11.Text = "" _
Or Text12.Text = "" Or Text13.Text = "" Or Text14.Text = "" Then
MsgBox "请填写完整的信息!"
Exit Sub
End If
Dim rs As New ADODB.Recordset
sql = "select * from 原始数据 where RWBH='" & Text14.Text & "'"
Set rs = transactsql(sql)
If rs.RecordCount > 0 Then
MsgBox "此任务编号已经存在,请重新输入!"
Text14.SetFocus
rs.Close
Else
sql = "select * from 原始数据"
Set rs = New ADODB.Recordset
Set rs = transactsql(sql)
With rs
If .BOF Then
.MoveFirst
Else
.MoveNext
End If
.AddNew 'Adodc1.Recordset
.Fields("Dmax") = Trim(Text1.Text)
.Fields("Lmax") = Trim(Text2.Text)
.Fields("Nmax") = Trim(Text3.Text)
.Fields("Nmin") = Trim(Text4.Text)
.Fields("ZKYV") = Trim(Text5.Text)
.Fields("HKYV") = Trim(Text6.Text)
.Fields("ZXGL") = Trim(Text7.Text)
.Fields("HXGL") = Trim(Text8.Text)
.Fields("ZJGV") = Trim(Text9.Text)
.Fields("HJGV") = Trim(Text10.Text)
.Fields("P") = Trim(Text11.Text)
.Fields("T") = Trim(Text12.Text)
.Fields("δ") = Trim(Text13.Text)
.Fields("RWBH") = Trim(Text14.Text)
.Update
.Close
End With
End If
adderr:
MsgBox Err.Description
End Sub