自定义的class
Public Class mycommand
Inherits System.Web.UI.UserControl
Dim cnConnection As SqlClient.SqlConnection
Dim cmdCommand As SqlClient.SqlDataAdapter
Dim strConnection As String
Dim strSQL As String
Dim dsData = New DataSet()
Public Sub tblexec(ByVal sender As Object, ByVal e As System.EventArgs)
'建立我的SQL语句
'strSQL = "SELECT * from jc_webdex "
If strConnection <> "" then
'建立数据库联接
cnConnection = New SqlClient.SqlConnection(strConnection)
'打开数据库联接
cnConnection.Open()
'为搜索建立一个新的command对象
cmdCommand = New SqlClient.SqlDataAdapter(strSQL, cnConnection)
'填充dataset对象
cmdCommand.Fill(dsData, "jc_webdex")
cnConnection.Close()
End If
End Sub
Public ReadOnly Property ResultView() As DataView
Get
'设置返回属性值
ResultView = dsData.tables("jc_webdex").defaultview
End Get
End Property
Public WriteOnly Property strCoun() As String
Set(ByVal Value As String)
'设置连接字符串
strConnection = Value
End Set
End Property
Public WriteOnly Property strsele() As String
Set(ByVal Value As String)
'设置SELE语句
strSQL = Value
End Set
End Property
End Class
在ASPNET中引用CLASS的相关代码
Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Dim mytbl As mycommand
Dim mydts As DataView
mytbl.strsele = " select ... from jc_webdex "
mytbl.strCoun = "data source= ......(略)"
mytbl.tblexec(ByVal sender As Object, ByVal e As System.EventArgs)//提示ByVal错误
mydts = mytbl.ResultView
End Sub
以上请各位指教,谢谢
如有低级错误别见笑,俺刚接触VB和ASPNET [
]