• We just launched and are currently in beta. Join us as we build and grow the community.

Retrieving Data Using DateTimePicker in VB.Net

wiltodos

Altcoin Explorer
Divine
W Rep
0
0
0
Rep
0
W Vouches
0
0
0
Vouches
0
Posts
62
Likes
141
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this tutorial, I will teach you how to retrieve data using datetimepicker in vb.net. This method has the ability to filter the data in a specific date by using the datetimepicker. In this way, you will be able to find out how many records will appear in the date that you have selected. See the procedure below.

Creating Database

Create a database named “profile
Do the following query to create a table and add the data inside the table.
  1. CREATE

    TABLE

    `profile`

    (
  2. `id`

    int

    (

    100

    )

    NOT

    NULL

    ,
  3. `name`

    varchar

    (

    100

    )

    DEFAULT

    NULL

    ,
  4. `email`

    varchar

    (

    100

    )

    DEFAULT

    NULL

    ,
  5. `photo`

    varchar

    (

    250

    )

    DEFAULT

    NULL

    ,
  6. `joindate`

    date

    NOT

    NULL


  7. )

    ENGINE

    =

    MyISAM DEFAULT

    CHARSET

    =

    latin1;

  8. --
  9. -- Dumping data for table `profile`
  10. --

  11. INSERT

    INTO

    `profile`

    (

    `id`

    ,

    `name`

    ,

    `email`

    ,

    `photo`

    ,

    `joindate`

    )

    VALUES


  12. (

    1

    ,

    'Jaison Joy'

    ,

    '[email protected]'

    ,

    'http://jaisonjoy.com//image/man.png'

    ,

    '2019-01-01'

    )

    ,
  13. (

    2

    ,

    'Vini'

    ,

    '[email protected]'

    ,

    'http://jaisonjoy.com/image/female.png'

    ,

    '2019-01-15'

    )

    ,
  14. (

    3

    ,

    'John'

    ,

    '[email protected]'

    ,

    'http://jaisonjoy.com/image/male.png'

    ,

    '2019-02-03'

    )

    ,
  15. (

    4

    ,

    'Test'

    ,

    'Test'

    ,

    NULL

    ,

    '2019-02-14'

    )

    ,
  16. (

    5

    ,

    'test2'

    ,

    'Test2'

    ,

    NULL

    ,

    '2019-02-14'

    )

    ;

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application in visual basic.
creating_vb_5.png

Step 2

Do the form just like shown below.
2019-02-14_2.png

Step 3

Go to the code view and add a namespace for mysql above the class.
  1. Imports MySql.Data.MySqlClient

Step 4

Inside the class, create a connection between MySQL and Visual Basic 2015. After that, declare all the classes that are needed.
  1. Dim

    con As

    MySqlConnection = New

    MySqlConnection("server=localhost;user id=root;password=;database=profile;sslMode=none"

    )
  2. Dim

    cmd As

    MySqlCommand
  3. Dim

    da As

    MySqlDataAdapter
  4. Dim

    dt As

    DataTable
  5. Dim

    sql As

    String

Step 5

Create a function for retrieving data in the database
  1. Dim

    con As

    MySqlConnection = New

    MySqlConnection("server=localhost;user id=root;password=;database=profile;sslMode=none"

    )
  2. Dim

    cmd As

    MySqlCommand
  3. Dim

    da As

    MySqlDataAdapter
  4. Dim

    dt As

    DataTable
  5. Dim

    sql As

    String

Step 6

Do the following codes for retrieving all the data in the database that will be display inside the datagridview in the first load of the form.
  1. Private

    Sub

    Form1_Load(sender As

    Object

    , e As

    EventArgs) Handles MyBase.Load
  2. sql = "SELECT * FROM `profile`"
  3. DataGridView1.DataSource = findData(sql)
  4. End

    Sub

Step 7

Write this code for filtering all the data that will be display inside the datagridview when the date is changed.
  1. Private

    Sub

    DateTimePicker1_ValueChanged(sender As

    Object

    , e As

    EventArgs) Handles DateTimePicker1.ValueChanged
  2. Dim

    todates As

    String
  3. todates = Format(DateTimePicker1.Value, "yyyy-MM-dd"

    )

  4. sql = "SELECT * FROM `profile` WHERE DATE(joindate) = '"

    & todates & "'"
  5. DataGridView1.DataSource = findData(sql)
  6. End

    Sub

For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.

 

452,496

335,120

335,128

Top