1、用SQL添加数据:
insert into 表名(字段1,字段2,字段3)
values(值01,值02,值03)
例如:
docmd.runsql"insert into EmpTable(Name,age,Duty,Salary) values('王明',35,'外贸总监',12500)"
2、用ADO的办法:
ADO比较复杂,给你一个完整的例子吧:
Dim strSqlfitjc As String
strSqlfitjc = "select * from *表"
Set RSfitjc = New ADODB.Recordset ‘定义一个ADO连接,连进数据库
RSfitjc.Open strSqlfitjc, cn, adOpenKeyset, adLockOptimistic ’打开连接
RSfitjc.addnew'添加一个纪录
RSfitjc.Fields("配件编号") = “style” ‘给每个字段赋值
.Update’储存赋值的新纪录
.Close 关闭连接
End With
Sub 添加_OnClick(ByVal sender As Object, ByVal e As EventArgs)Dim SqlConn As New SqlConnection
SqlConn.ConnectionString = "Persist Security Info=trueInitial Catalog=Datauid=sapwd=123456Data Source=."
SqlConn.Open()
Dim SqlCmd As New SqlCommand
SqlCmd.Connection = SqlConn
SqlCmd.CommandText = "Insert into #table (客户编号,性别,电话,电子信箱,地址,住址)values('" &客户编号.Text &"','" &性别.Text &"','" &电话.Text&"','" &电子信箱.Text &"'," &地址.Text &",'" &住址.Text &"')"
SqlCmd.ExecuteNonQuery()
SqlConn.Close()
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)