asp.net(vb.net)连接sql server 2000数据库的连接模块(module)
2004-12-10 16:57:50 来源:WEB开发网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)
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››VB 通过Grid Report 显示时间
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
更多精彩
赞助商链接