Private Sub Command1_Click()
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = "Provider=SQLOLEDB.1;Password=111;Persist Security Info=True;User ID=sh;Initial Catalog=shks;Data Source=LENOVO-PC\SQLEXPRESS;"
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "select * from 销售表 where 产品编号='" & Trim(Text1.Text) & "' and 销售商编号='" & Trim(Text2.Text) & "'"
If cmd.Execute.EOF Then
MsgBox "记录不存在!"
Else
cmd.CommandText = "update 销售表 set 销售时间='" & Trim(Text3.Text) & "',销售数量='" & Trim(Text4.Text) & "',销售金额='" & Trim(Text5.Text) & "' where 产品编号='" & Trim(Text1.Text) & "' and 销售商编号='" & Trim(Text2.Text) & "'"
cmd.Execute
MsgBox "修改成功!"
End If
cnn.Close
End Sub
可以先通过查询语句,可以判断是否返回记录?