相似的两段代码,下面这一个可以用,为什么上面问题贴的却不能用? 求解Private Sub Command1_Click() On Error Resume Next Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim mrc As New ADODB.Recordset If Text1(0).Text = "" Or Text1(1).Text = "" Or Text1(2).Text = "" Or DataCombo1.BoundText = "" Then MsgBox "信息不完整,无法保存!" Else cnn.ConnectionString = "FILE NAME=C:\Program Files\Common Files\ODBC\Data Sources\student_link.dsn" cnn.Open Set rs = cnn.Execute("insert into stud_grade(stud_id,name,course_id,grade)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + DataCombo1.BoundText + "','" + Text1(2).Text + "')") txtsql = "select * from stud_grade where stud_id='" + Text1(0).Text + "'and name='" + Text1(1).Text + "'and course_id='" + DataCombo1.BoundText + "'and grade='" + Text1(2).Text + "'" Set mrc = cnn.Execute(txtsql)
On Error Resume Next
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim mrc As New ADODB.Recordset
If Text1(0).Text = "" Or Text1(1).Text = "" Or Text1(2).Text = "" Or DataCombo1.BoundText = "" Then
MsgBox "信息不完整,无法保存!"
Else
cnn.ConnectionString = "FILE NAME=C:\Program Files\Common Files\ODBC\Data Sources\student_link.dsn"
cnn.Open
Set rs = cnn.Execute("insert into stud_grade(stud_id,name,course_id,grade)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + DataCombo1.BoundText + "','" + Text1(2).Text + "')")
txtsql = "select * from stud_grade where stud_id='" + Text1(0).Text + "'and name='" + Text1(1).Text + "'and course_id='" + DataCombo1.BoundText + "'and grade='" + Text1(2).Text + "'"
Set mrc = cnn.Execute(txtsql)
If mrc.EOF = True Then
MsgBox "添加失败!", , "信息提示"
Else
Me.Adodc4.Refresh
Form7.Adodc1.Refresh
MsgBox "添加成功!", , "信息提示"
End If
cnn.Close
End If
End Sub