Data room charging system Personal Edition-how to use the datagridview control?

Source: Internet
Author: User

Charging System in VB. NET data centerDuring personal refactoring, I found that the mshflexgrid control in VB6.0 was used in? Therefore, the datagridview control is displayed. But how can this control be used? Let's take the "query of collected amount" in the data room charging system as an example to explain how to use the datagridview control.


The following figure shows the page for querying the charge amount:


Of course, the gray control at the bottom of the interface is the datagridview. So. How can I display the data found in the database in the datagridview? What is the returned value during layer-D query? Is it a Boolean value? Table? Or entity? Of course, a Boolean value is not returned because the data must be displayed in the datagridview. The answer is to return a table or an object. Next, let's take the returned table as an example. Let's take a look at the implementationCodeRight.


U-Layer Code:

 

Public class formui_querycollectsum 'query button private sub btnquery_click (byval sender as system. object, byval e as system. eventargs) handles btnquery. click 'instantiate two object class objects in total, assign the start date and end date to the two object class objects' respectively to define an object class object, and instantiate this object dim begindata as model. model_czrecord = new model. model_czrecord: assigns the time content in the start date text box to the indata object of the object class. cz_date = datetimebegin. text. tostring () 'defines another object class Object dim enddata as model. model_czrecord = new model. model_czrecord: assigns the time content in the end date text box to the object class Object enddata. cz_date = datetimeend. text. tostring () 'defines a layer B object, which is used to return the result of layer B dim UB as BLL. bll_querycollectsum = new BLL. bll_querycollectsum dim A as able call the method of B layer a = ub. query_rechargerecord (begindata, enddata) 'displays the returned values in the datagridview datagridatagridatagridatagridatagridatagridatagridatagridatagridatagridatagridatasource

 


Layer B code:

 

 

 
Public class bll_querycollectsum defines a function to return the query result of layer D. Public Function query_rechargerecord (byval model1 as model. model_czrecord, byval model2 as model. model_czrecord) as able defines a D-layer object dim BD as Dal. dal_querycollectsum = new Dal. dal_querycollectsum dim A as able call the D-layer function a = BD. query_rechargerecord (model1, model2 )'!! Note that there are two parameters !!!! 'Return value is a table return a end functionend class

 


D-layer functions:

 

 

 
'Define a function to query the data in the table public function query_rechargerecord (byval tstdata as model. model_czrecord, byval txtdata as model. model_czrecord) as able 'query statement dim sqlstr as string sqlstr = "select * From czrecord where cz_date> '" & tstdata. cz_date & "'and cz_date <'" & txtdata. cz_date & "'"' Run dim myadapter as sqldataadapter = new sqldataadapter (sqlstr, Conn) dim mytable as new datatable () myadapter. fill (mytable) return mytable end functionend class

The rough code is introduced here.The difficulty is that you do not knowHow to display in the datagridview control. With the above Code, we hope to provide you with some ideas. Of course, I know the datatable type, and the following sentence is important.

 
Datagridview1.datasource =

 

 






 

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.