登录模块加载中...
会员投稿 投稿指南 今天是:
打印本页 | 关闭窗口 | 双击滚屏 您的位置首页>>网页制作学习园地>>NET教程>>net数据库应用>>asp.net(vb.net)连接sql server 2000数据库的连接模块(module)
asp.net(vb.net)连接sql server 2000数据库的连接模块(module)
来源:不详 ‖ 作者:佚名 ‖ 点击: ‖ 时间:07-12-17 13:05:12 ‖ 【 】‖ 我要投稿
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)


加入收藏:  加入收藏夹  | 发送给好友:  发送给好友
责任编辑:0
请文明参与讨论,禁止漫骂攻击。  
网友评论