谁能提供一下asp.net2.0的数据库访问类
我是从1.1开始学的,虽然2.0可以完全运行1.1的类库,但是没有体会2.0的优越性能,如强类型的使用,能使用事务处理、存储过程、取数据(datareader、datatable、dataset)。
所以请高手给个全点的数据库访问类。谢谢!!
------解决方案--------------------petshop 4.0里带 的sqlhelper可以么
------解决方案--------------------微软企业库2.0
------解决方案--------------------自己写的,仿照PetShop3,有些改动。
'-------------------------------------------------
' ClassName:PublicDAL For SQL server
' Author:Eraysky(卞吉东)
' Company:Star-hope(斯达浩普)
' Function:基本数据操作类,提供常用的数据库连接查询执行功能。
' History:2006-10建类,2007-2更新
' 注意:
' 1 如果用此类操作数据库。各业物数据库类的SQL语句参数不再为?,而是@userid的形式
' 2 各实体业务类的获取参数getUserParameter方法也改为Sql形式
' 3 连接字符串直接连接SQL数据库,而不连接ODBC。
'-------------------------------------------------
Imports System.Data
Imports eraysky.Utility
Imports System.Data.SqlClient
Imports System.Configuration
Public Class PublicSQLDAL
Public Shared ReadOnly constr1 As String = ConfigurationManager.ConnectionStrings.Item( "erayskyConstr1 ").ToString
Public Shared ReadOnly constr2 As String = ConfigurationManager.ConnectionStrings.Item( "erayskyConstr2 ").ToString
Public Shared ReadOnly constr3 As String = ConfigurationManager.ConnectionStrings.Item( "erayskyConstr3 ").ToString
Public Shared ReadOnly Con1 As New SqlConnection(ConStr1)
Public Shared ReadOnly Con2 As New SqlConnection(ConStr2)
Public Shared ReadOnly Con3 As New SqlConnection(constr3)
'执行非查询语句,insert,update
Public Shared Function EXESQL(ByVal conn As SqlConnection, ByVal SQL As String, ByVal parms() As SqlParameter) As Integer
Dim result As Integer
If conn.State = ConnectionState.Closed Then conn.Open()
Dim cmd As SqlCommand = New SqlCommand
Try
PrepareCommand(cmd, conn, Nothing, CommandType.Text, SQL, parms)
result = cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Catch ex As Exception
result = -1
End Try
Return result
End Function
'执行查询语句,返回一个dataset
Public Shared Function GETDataSet(ByVal conn As SqlConnection, ByVal SQL As String, ByVal parms() As SqlParameter) As DataSet
Dim cmd As SqlCommand = New SqlCommand
Dim result As New DataSet
PrepareCommand(cmd, conn, Nothing, CommandType.Text, SQL, parms)
Try
Dim myadapter As SqlDataAdapter
myadapter = New SqlDataAdapter(cmd)
myadapter.Fill(result)
Catch ex As Exception
End Try
Return result
End Function
'执行查询语句,返回reader。
Public Shared Function GETReader(ByVal conn As SqlConnection, ByVal SQL As String, ByVal parms() As SqlParameter) As SqlDataReader
Dim cmd As SqlCommand = New SqlCommand
PrepareCommand(cmd, conn, Nothing, CommandType.Text, SQL, parms)
Dim result As SqlDataReader
Try
result = cmd.ExecuteReader()
Catch ex As Exception
result = Nothing
End Try
Return result
End Function
'执行查询语句,返回查询结果第一行,第一列值。
Public Shared Function GETScalar(ByVal conn As SqlConnection, ByVal SQL As String) As Object
Dim cmd As SqlCommand = New SqlCommand
PrepareCommand(cmd, conn, Nothing, CommandType.Text, SQL, Nothing)