vb.net连接SQL Server 2000

求vb.net连接SQL Server 2000的代码?请写清楚点.
2024-12-30 14:22:13
推荐回答(3个)
回答1:

asp.net(vb.net)连接sql server 2000数据库的连接模块(module)
Module MdlCommon
Public txtSQL As String '存放SQL语句
Public DBSet As DataSet '查询得到的记录集
Public ErrorMsg As String '存放错误信息

Public Function ExecuteSQL(ByVal strSQL As String, ByRef errMsg As String) As DataSet
Dim cnn As SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand()
Dim adpt As SqlClient.SqlDataAdapter
Dim rst As New DataSet()
Dim SplitSQL() As String
errMsg = ""
Try
SplitSQL = Split(strSQL)
cnn = New SqlClient.SqlConnection("data source=(local);initial catalog=urp;user id=sa;pwd=1234")

If InStr("INSERT,DELETE,UPDATE", UCase$(SplitSQL(0))) Then
cmd.Connection = cnn
cmd.Connection.Open()
cmd.CommandText = strSQL
cmd.ExecuteNonQuery()
Else
adpt = New SqlClient.SqlDataAdapter(strSQL, cnn)
adpt.Fill(rst)
ExecuteSQL = rst
End If
Catch ex As Exception
errMsg = ex.Message
Finally
rst = Nothing
cnn = Nothing
End Try
End Function End Module
调用时在asp.net后台写上txtSQL="SELECT ....FROM........";
DBSet=ExecuteSQL(txtSQL,ErrorMsg)

回答2:

using system.data
using system.data.SqlClient
dim strCon as string
strCon="provider=SQLOLEDB;SERVER=服务器IP;uid=用户名;pwd=密码;database=数据库名"
dim con as SqlConnection
con = new SqlConnection(strCon)

回答3:

http://topic.csdn.net/t/20050324/11/3876944.html