Vb. NET Edition computer room charge system-datagridview Application

Source: Internet
Author: User

in fact, just started knocking at the computer room, just used to DataGridView time, always appear to be powerless, first to learn, read a lot of information, but according to write, I do not know where to start, so, when they use query SQL statement, and DataGridView display, this function can not be realized, but here to everyone to write, if there is any bad will, please point out:

First edition:

Window design:

The required controls:

DateTimePicker, datasets, DataGridView

Three steps to grasp:

The first step: Use the view to create a view of the results you want (assuming that a table can be solved, you can just use one query).

Second Step: Query view returns DataTable

The third step: directly let the DataSource of the GridView is equal to the data in the DataTable.

Detailed implementation method:

Imports System.Data.SqlClientImports System.Windows.FormsPublic Class frmopergetcharge Private Sub Btnqurry_click ( ByVal sender as Object, e as EventArgs) Handles Btnqurry. Click Dim start_datetime As String is defined as string because the field in the SQL table is a string type Dim End_datetime As String start_d Atetime = convert.tostring (Datetimepicker1.value + "00:00:00") ' is set to a string type can also be directly compared, plus the subsequent 00:00:00 is due to the data in the database when there is time En D_datetime = convert.tostring (datetimepicker2.value) ' receives data from DateTimePicker Dim strconnection as String = "server=m X Database=reconsitutioncharge_sys; User Id=sa; password=123456 "Dim sqlConnection1 As New SqlConnection (strconnection) Dim dataAdapter As New Sqldataadapte R Dim Dst As New DataSet ' stored in dataset Dim DT as new DataTable ' Receive query result Sqlconnection1.open () Di        M SQL as String = "SELECT * from T_recharge_dal Where @Start_dateTime <= datetime and datetime <= @End_dateTime" Dim cmd as SqlCommand = New SqlCommand (sqL, SqlConnection1) cmd. Parameters.Add (New SqlParameter ("@Start_dateTime", Start_datetime)) ' Assign value, and pass cmd. Parameters.Add (New SqlParameter ("@End_dateTime", End_datetime)) ' Assignment, transfer dataadapter.selectcom Mand = cmd DataAdapter.Fill (DST, "recharge") ' passes the data in the DataAdapter to the DataSet dt = DST.  Tables ("Recharge") returns the data in the dataset to the DataTable Sqlconnection1.close () Datagridview1.autogeneratecolumns = True ' Proactively create columns Datagridview1.datasource = DT ' data source End subend Class

In fact, this should also be done with three layers.




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.