在asp.net (vb) 中如何创建 能接受数据库连接字符和SQL语句字符并能返回数据集(TABLE对象)的公共函数? (200分)

  • 主题发起人 主题发起人 smallbs
  • 开始时间 开始时间
ICollection CreateSource()
{
int StartIndex;
//设定导入的起终地址
StartIndex = CurrentPage*PageSize;
string strSel = "select * from Score";
DataSet ds = new DataSet();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,StartIndex,PageSize,"Score");
return ds.Tables["Score"].DefaultView;
}
看看吧,有参考价值
 
onlyonekgx 先生:
 非常感谢您的指导。俺刚刚接触ASP.NET和VB,起步时甚至搞不清如何加载和使用
这些自定义函数,希望能求一个成功的实例学习学习,给个例子好吗? 
为了表示感谢,分数会再加 [:D]
my email fsxnjjcj@jlonline.com
 
看M$的.Net帮助教程不是很好吗?
 
这个嘛.....我想看一下你的代码是怎么写的先?
 
自定义的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 [:D]
 
试试
》mytbl.tblexec(ByVal sender As Object, ByVal e As System.EventArgs)
mytbl.tblexec(sender, e)
偶也菜菜 :)
 
有两处错误
一处是ZRWeng说的 mytbl.tblexec(sender, e) //mytbl.tblexec(ByVal sender As Object, ByVal e As System.EventArgs)
另一处是 Dim mytbl = New mycommand() //Dim mytbl As mycommand
谢谢! 搞定.
 
多人接受答案了。
 
后退
顶部