vb中怎么操作SQL数据库?

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:35:47
比如我在VB中想执行一条更改的SQL语句,update table set tm1=111 where tm1=222

用ADODC也可以,ADODB也可以,其他的也可以,需要怎么写?请写详细点,谢谢

Private Sub Command1_Click()

Dim conn As ADODB.Connection
Dim strSql As String
Set conn = OpenConnForSqlServer("127.0.0.1", "sa", "sa")
strSql = "update table set tm1=111 where tm1=222 "
RunTrans strSql, conn

end sub
Public Function OpenConnForSqlServer(ByVal ServerName As String, ByVal UserId As String, ByVal PassWord As String, Optional ByVal DateBaseName As String = "") As ADODB.Connection
Dim AdoConn As New ADODB.Connection
Dim strConn As String
With AdoConn
strConn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=" & UserId & ";Password=" & PassWord & ";Data Source=" & ServerName
If DateBaseName <> "" Then strConn = strConn & ";database=" & DateBaseName
.ConnectionString = strConn
.Open
End With