search
HomeCommon ProblemHow datagridview displays data

How datagridview displays data

Jan 12, 2021 pm 01:56 PM
datagridview

How to display data in datagridview: 1. Find the "DataSource" property in the property window and select "Dataset"; 2. Select "Data Connection" and click "New Connection"; 3. Join the link dialog Change the data source in the box; 4. Select the database in the data field, and then click "OK".

How datagridview displays data

The operating environment of this article: Windows 7 system, DataGridView control, Dell G3 computer.

Methods for datagridview to display data:

The first method is to set the data through properties

First find the DataSource property in the property window , click the drop-down box. This is the first time to use it. If you have added it before, click to add the data source

How datagridview displays data

Select the data type, next step, select the data set, next step

How datagridview displays data

Select the data connection and click New Connection

How datagridview displays data

Change the data source (the SQL Server database I use) in the Join Link dialog box and click the drop-down Select the server name in the box (the dot defaults to your own server). Then select the database under Connect to Data. If the test link passes, click OK. At this time, you return to the data configuration wizard. Click Next to select the table you want to display in the database.

How datagridview displays data

After the addition is completed, the execution window data will be displayed

How datagridview displays data

Another method is to pass Write code to load data

<span style="font-family:KaiTi_GB2312;font-size:18px;">    &#39;定义一个函数查找规定日期内的收取金额
    Public Function check_money(ByVal tstRecharge As Model.RechargeModel) As DataTable
        Dim strSQL As String = "select * from Recharge_info where rechargeDateTime between @startdatetime and @enddatetime"
        Dim params As SqlParameter() = {New SqlParameter("@startdatetime", tstRecharge.start_datetime), New SqlParameter("@enddatetime", tstRecharge.end_datetime)}
        Dim helper As New SqlHelper
        Dim dat = helper.GetDataTable(strSQL, CommandType.Text, params) &#39;调用sqlhelper
        Return dat &#39;返回查到的数据表
    End Function</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"> Dim db As New DAL.CkeckMoneyDAL &#39;定义一个D层对象,用来调用D层函数
    &#39;定义一个函数,用来检查D层查找金额返回的数据
    Public Function check_return(model As Model.RechargeModel) As DataTable
        Dim dat = db.check_money(model)
        If dat.Rows.Count = 0 Then &#39;检查D层返回的数据表中是否有数据
            Return Nothing
        Else
            Return dat
        End If
    End Function</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"> Dim thisRecharge As New Model.RechargeModel &#39;定义一个实体层对象,用来接收起止时间
        thisRecharge.start_datetime = DateTimePicker1.Text
        thisRecharge.end_datetime = DateTimePicker2.Text
        Dim ub As New BLL.CheckMoneyBLL &#39;定义一个B层对象,用来调用B层函数
        If ub.check_return(thisRecharge) Is Nothing Then
            MsgBox("该时间段内没有记录,请又一次设置时间段!", MsgBoxStyle.Exclamation, vbOKOnly)
        Else
            dvwTitles.DataSource = ub.check_return(thisRecharge) &#39;把查到的数据传给datagridview
        End If</span>

Display results:

How datagridview displays data

Both methods have their own advantages and disadvantages. We need to choose according to our actual situation. . When we only need to display the data of the entire table or there is not much data in the table, the first method is the easiest and does not require writing any code. Suppose we want the data to be displayed selectively. For example, the picture above only displays the data from June 18th to June 20th. Although it seems cumbersome to write code, the display results are clear at a glance, which prevents us from searching for a large amount of data. The data we need greatly improves efficiency.

Related free learning recommendations: php programming (video)

The above is the detailed content of How datagridview displays data. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use