'连接语句:
cn.Open "Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=数据库名;Data Source=(local)"
'更新语句:
Dim supdate As String
supdate = " Update 表名 set 列值 = "
supdate = supdate & "'" & 控件名 & "'" supdate = supdate & " ,列值 = "
supdate = supdate & "'" & Text1.Text & "'"
supdate = supdate & " ,列值 = "
supdate = supdate & "'" & Text4.Text & "'" supdate = supdate & " where pingzhong_id = "
supdate = supdate & "'" & Text2.Text & "'"
'添加语句:
Dim sinsert As String
sinsert = "Insert Into 表名("
sinsert = sinsert & "id,"
sinsert = sinsert & "列值,"
sinsert = sinsert & "列值,"
sinsert = sinsert & "列值,"
sinsert = sinsert & "列值,"
sinsert = sinsert & "列值)"
sinsert = sinsert & "Values ("
sinsert = sinsert & "'" & Text1.Text & "',"
sinsert = sinsert & "'" & 控件名 & "',"
sinsert = sinsert & "'" & 控件名 & "',"
sinsert = sinsert & "'" & 控件名 & "',"
sinsert = sinsert & "'" & 控件名 & "',"
sinsert = sinsert & "'" & 控件名 & "')"
'执行语句:
Dim cmd1 As New ADODB.Command
With cmd1
.ActiveConnection = cn
.CommandType = adCmdText
.Prepared = True
.CommandText = sinsert '执行的SQL语句
.Execute
End With
cn.Close