"Transfer" of a set with Entity parameters wildcard under a three-tier architecture"

Source: Internet
Author: User

I have read the three methods to achieve "returning the query results of two tables in one (Group) query". Most of my colleagues in this blog may be interested in the last method. That is, the query result is put into the generic set, and the two put the generic set into another new generic set. The parameter of the new set is object. (Link: http://blog.csdn.net/u010191243/article/details/38798773)

Layer D code:

Public Function querycardstudentinfo (byval encard as cardentity, byval enstudent as studententity) as List (of object) implements icarddal. dim strquerycardinfo as string dim same as string dim dtquerycardinfo as datatable dim same as datatable dim mycardlist as List (of cardentity) dim mystudentlist as List (of studententity) 'Union query SQL clause: strquerycardinfo = "select C. comment, C. money, C. status from t_card as C inner join t_student as s on C. cardno = S. cardno where ([email protected]) "'find information in the card table and put it in mycardlist strquerycardinfo =" select * From t_card where [email protected] "dim paracard as sqlparameter () = {New sqlparameter ("@ cardno", encard. cardno)} dtquerycardinfo = sqlhelper. executeselect (strquerycardinfo, commandtype. text, paracard) mycardlist = ctype (listhelper. converttolist (of cardentity) (dtquerycardinfo), Global. system. collections. generic. list (of Global. entity. cardentity) 'find the information in the student table and put it in the mystudentlist strquerystudentinfo = "select * From t_student where [email protected]" dim parastudent as sqlparameter () = {New sqlparameter ("@ cardno", enstudent. cardno)} dtquerystudentinfo = sqlhelper. executeselect (strquerystudentinfo, commandtype. text, parastudent) mystudentlist = ctype (listhelper. converttolist (of studententity) (dtquerycardinfo), Global. system. collections. generic. list (of Global. entity. studententity) dim mylist as new list (of object) 'creates a new list mylist. add (mycardlist) 'add mycardlist mylist. add (mystudentlist) 'add mystudentlist return mylist end Function

Although the Dal layer is well written, what we need is that the U layer can still find the attributes of the object and assign values to it. Otherwise, how good do you think of the D Layer, what a good write is useless, and the U layer cannot be implemented! So how to find its properties on the u layer?

To achieve this effect, we must first understand the principle of this design:

First, we put the object results into the generic collection, that is, "mystudent =…" in the code ......" This is a large string of code. We can think of the content in its entity as a pack of nails, and load it into a generic set as a pack ".

Then, load these generic sets into a new mylist, that is, mylist. Add (mycardlist); it is like loading the packaged nails ".

Finally, return! Return mylist, that is, drive the nail to the U layer.

So what should we do at the U layer?

Of course it is done first!

Then? Then we will split the package!


Let's look at the U-Layer Code:

Private sub btn_on_click (sender as object, e as eventargs) handles btn_on.click 'to determine whether the card number is blank and whether it is a number if txtcardno. TEXT = "" Then msgbox ("the card number cannot be blank", "prompt") txtcardno. focus () Exit sub else if isnumeric (txtcardno. text) = false then msgbox ("Enter the card number", "prompt") txtcardno. focus () Exit sub end if Dim Enline as new entity. lineentity 'defines the Host object. In the following example, assign dim fline as new facade to the specific object attribute. fline' defines the appearance of Enline. cardno = txtcardno. text' input the card number Enline. ondate = format (date. today, "yyyy/mm/DD") Enline. ontime = format (date. now, "HH: mm") Enline. status = "running" Enline. username = frmlogin.txt username. text dim myline as new list (of object) 'key step. The defined parameter is the object's generic set variable try myline = fline. loginon (Enline) 'transfers the execution result on the machine to the defined generic set.' display data dim card as new list (of entity. cardentity) dim student as new list (of entity. studententity) card = myline. item (0) 'key step: Pass the content in the first item in the generic set to lmoney in the generic set variable with the cardentity parameter. TEXT = card. item (0 ). money. tostring' value: Student = myline. item (1) 'transmits the content of the second item in the generic set to lapartment in the generic set variable with the parameter studententity. TEXT = student. item (0 ). department. tostring 'note, student here. item (0) Same as the card on the same side. item (0) is of the same level, and they are independent lgrade. TEXT = student. item (0 ). grade. tostring lstudentname. TEXT = student. item (0 ). studentname. tostring lcardno. TEXT = txtcardno. text lsex. TEXT = student. item (0 ). sex. tostring lclass. TEXT = student. item (0 ). stclass. tostring londate. TEXT = now. date lontime. TEXT = now. hour & ":" & now. minute call fline. queryonlineno (Enline) 'queries the number of people under the catch ex as exception msgbox (ex. message, "prompt") end try end sub

Renewal Process: Card = myline. item (0) and student = myline. item (1), that is, the myline that contains two result sets (returned card information and student information) is unloaded to two places respectively.

Packing process: lmoney. Text = card. Item (0). Money. tostring

Although writing like above can implement the computer, there are still some problems.

If I first upload card number 1 and then card number 2, the information of card number 2 on the interface will overwrite 1. If we enter card number 1 again and click "computer", no information on card number 1 will appear on the interface.

I tried to remove the content under the comment "'display information' above ...... The Catch Block still cannot solve the problem. We look forward to your solutions! Of course, I will try again, and update it as soon as possible ~

 
 

"Transfer" of a set with Entity parameters wildcard under a three-tier architecture"

Related Article

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.