自己写的一些类代码

以前在写类代码时候,改写了一些自定义的类代码,自己在做CManage时,一些传统的类老是要重复地写。有点烦,在参考同学的类代码中。自己也写了一些类。以下就是这个作业的类的代码。

这里是一个类,存储字段的类
ExpandedBlockStart.gif ContractedBlock.gif Public   Class Parm Class Parm
InBlock.gif    
Public str1 As String
InBlock.gif    
Public str2 As String
InBlock.gif    
Public str3 As String
InBlock.gif    
Public str4 As String
InBlock.gif    
Public str5 As String
InBlock.gif
InBlock.gif    
Public DataKeyField As String
InBlock.gif    
Public DataTextField As String
InBlock.gif    
Public DataValueField As String
InBlock.gif    
Public objCtr As Object
ExpandedBlockEnd.gif
End Class
None.gif   ' 返回sqldatareader(数据读取器)(用于查找数据)
ExpandedBlockStart.gifContractedBlock.gif
     Public   Function ReturnReader() Function ReturnReader(ByVal myParm As Parm) As SqlDataReader
InBlock.gif        
Dim Cmd As SqlCommand = ReturnCmd(myParm)
InBlock.gif        
Dim MyDtr As SqlDataReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
InBlock.gif        
Return MyDtr
ExpandedBlockEnd.gif    
End Function

ExpandedBlockStart.gifContractedBlock.gif    
Public   Function ReturnCmd() Function ReturnCmd(ByVal myParm As Parm) As SqlCommand
InBlock.gif        con.Open()
InBlock.gif        
Dim Cmd As SqlCommand
InBlock.gif        Cmd 
= New SqlCommand(myParm.str1, con)
InBlock.gif        Cmd.CommandType 
= CommandType.StoredProcedure
InBlock.gif        
Return Cmd
ExpandedBlockEnd.gif    
End Function

None.gif    
' 数据控件的数据绑定(通用于Dropdownlist,datagrid,datalist)(数据源是Datareader)
ExpandedBlockStart.gifContractedBlock.gif
     Public   Sub DataControlDataReaderBinding() Sub DataControlDataReaderBinding(ByVal myp As Parm)
InBlock.gif        myp.objCtr.DataSource 
= ReturnReader(myp)
InBlock.gif        
If TypeOf (myp.objCtr) Is DataList Or TypeOf (myp.objCtr) Is DataGrid Then
InBlock.gif            
If myp.DataKeyField <> "" Then
InBlock.gif                myp.objCtr.DataKeyField 
= myp.DataKeyField
InBlock.gif            
End If
InBlock.gif            myp.objCtr.DataBind()
InBlock.gif        
ElseIf TypeOf (myp.objCtr) Is DropDownList Then
InBlock.gif            myp.objCtr.DataTextField 
= myp.DataTextField
InBlock.gif            myp.objCtr.DataValueField 
= myp.DataValueField
InBlock.gif            myp.objCtr.DataBind()
InBlock.gif        
End If
InBlock.gif        con.Close()
ExpandedBlockEnd.gif    
End Sub
None.gif    Dim  myTest  As   New  Test
ExpandedBlockStart.gifContractedBlock.gif    
Private   Sub ddlBindClass() Sub ddlBindClass()
InBlock.gif        
Dim myParm As New Parm
InBlock.gif        myParm.str1 
= "sp_SelectNewsClass"
InBlock.gif        myParm.objCtr 
= ddlBindNewsClass
InBlock.gif        myParm.DataTextField 
= "ClassName"
InBlock.gif        myTest.DataControlDataReaderBinding(myParm)
ExpandedBlockEnd.gif           
End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值