以程式设计方式建立应用程式和 SQL Server 资料库间的连接
以下程式码建立 SqlConnection 物件、设定 SqlConnection.ConnectionString 属性并开启连接。
' Visual BasicPublic Sub ConnectToSql()
Dim conn
As New SqlClient.SqlConnection
' TODO: Modify the connection string and include any ' additional required properties for your database. conn.ConnectionString = & _
"integrated security=SSPI;data source=SQL Server Name;" & _
"persist security info=False;initial catalog=northwind"
Try conn.
Open()
' Insert code to process data. Catch ex
As Exception MessageBox.Show("Failed to connect to data source")
Finally conn.
Close()
End TryEnd Sub你有装VS2003的MSDN吗?如果有的话在VS里搜寻SQL可以找到上面这段~