Public Class getdata
Public Shared myconn As SqlClient.SqlConnection
Public Shared Function getdatareader(ByVal sql As String) As SqlClient.SqlDataReader
Dim myCmd As SqlClient.SqlCommand
myCmd = New SqlClient.SqlCommand(sql, myconn)
getdatareader = myCmd.ExecuteReader()
End Function
Public Shared Function executesql(ByVal sql As String)
Dim myCmd As SqlClient.SqlCommand
myCmd = New SqlClient.SqlCommand(sql, myconn)
myCmd.ExecuteNonQuery()
End Function
Public Shared Function getdataview(ByVal sql As String, ByVal strTable As String) As DataView
Dim myDataAdapter As SqlClient.SqlDataAdapter
Dim myDataSet As DataSet
myDataAdapter = New SqlClient.SqlDataAdapter(sql, myconn)
myDataSet = New DataSet
myDataAdapter.Fill(myDataSet, strTable)
Dim myTable As DataTable = myDataSet.Tables(strTable)
getdataview = New DataView(myTable)
End Function
End Class
调用
getdata.myconn = New SqlClient.SqlConnection
getdata.myconn.ConnectionString = (xinxi.stringconnection)