如何用VB编程将数据存储到SQL数据库中

要具体的程序
2024-11-24 20:58:41
推荐回答(3个)
回答1:

记得引用微软的控件Microsoft ActoveX Date Objects 2.6 Library
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim constr As String
Dim sqlstr As String
constr = "driver={sql server};server=你的服务器;uid=用户名;pwd=密码;database=数据库"
con.ConnectionString = constr
con.Open
sqlstr = "insety into table (field,field1) values('" & text1.text & "','" & text2.text & "')"
SQLconn.Execute sqlstr

回答2:

Dim lj As String = "Data Source=数据库;Initial Catalog=服务器;Persist Security Info=True;User ID=用户名;Password=密码"
Dim con As New Data.SqlClient.SqlConnection(lj)
Dim sql2 As String = "select * from tblworkcenter where workcentercode=" + "'" + WorkCenterCode + "'"
con.Open()
Dim cmd As New Data.SqlClient.SqlCommand(sql2, con)
Dim myreader As Data.SqlClient.SqlDataReader = cmd.ExecuteReader
If myreader.Read() Then
base.Alert("Data duplication, please re-enter")
Exit Sub
End If
con.Close()

回答3:

insert语句

数据库方面的我建议你去查别人的模块
一般写代码的都会把这个建成一个模块
以后程序中使用的时候可以直接提用