Some self-written class code

Source: Internet
Author: User
In the past, some custom class code was rewritten when writing class code. When I was doing cmanage, some traditional classes always had to be repeatedly written. A little annoying. In the class code for reference. I also wrote some classes. The following is the code of the job class.

Here is a class that stores Fields
Public class parmclass parm
Public str1 as string
Public str2 as string
Public str3 as string
Public str4 as string
Public str5 as string

Public datakeyfield as string
Public datatextfield as string
Public datavaluefield as string
Public objctr as object
End Class 'returns sqldatareader (data reader) (used to find data)
Public Function returnreader () function returnreader (byval myparm as parm) as sqldatareader
Dim cmd as sqlcommand = returncmd (myparm)
Dim mydtr as sqldatareader = cmd. executereader (commandbehavior. closeconnection)
Return mydtr
End Function
Public Function returncmd () function returncmd (byval myparm as parm) as sqlcommand
Con. open ()
Dim cmd as sqlcommand
Cmd = new sqlcommand (myparm. str1, con)
Cmd. commandtype = commandtype. storedprocedure
Return cmd
End Function
'Data binding of Data Controls (generally used in dropdownlist, DataGrid, datalist) (the data source is datareader)
Public sub datacontroldatareaderbinding () sub datacontroldatareaderbinding (byval myp as parm)
Myp. objctr. datasource = returnreader (myp)
If typeof (myp. objctr) is datalist or typeof (myp. objctr) is DataGrid then
If myp. datakeyfield <> "" then
Myp. objctr. datakeyfield = myp. datakeyfield
End if
Myp. objctr. databind ()
Elseif typeof (myp. objctr) is dropdownlist then
Myp. objctr. datatextfield = myp. datatextfield
Myp. objctr. datavaluefield = myp. datavaluefield
Myp. objctr. databind ()
End if
Con. Close ()
End sub dim mytest as new test
Private sub ddlbindclass ()
Dim myparm as new parm
Myparm. str1 = "sp_selectnewsclass"
Myparm. objctr = ddlbindnewsclass
Myparm. datatextfield = "classname"
Mytest. datacontroldatareaderbinding (myparm)
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.