Help me check? I think there's something wrong with these codes especially to the date of birth(chodob) when i start debugging the database don't have any columns :(
Customer name = txtstdid
Name = txtstdname
Gender/Sex = cbosex
Date of Birth = chodob1, chodob2, chodob3
Identification card number = txtic
Passport number = txtpassn
Phone number = txtpn
Date of depature = dod1, dod2, dod3
Address = txtaddress
Address at the point of arrival = txtaapoa

Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            'open connection
            cnn.Open()
        End If

        Dim da As New OleDb.OleDbDataAdapter("SELECT txtstdid as [ID], " & _
                                             "txtstdname as [Name], cbosex as [Gender], chodob1 as [Date Of Birth], chodob2 as [Date Of Birth], chodob3 as [Date Of Birth], txtic as [Identification Number Card], txtpassn as [Passport Number], txtpn as [Phone Number], dod1 as [Date Of Departure], dod2 as [Date Of Departure], dod3 as [Date Of Departure], txtaddress as [Address], txtaapoa [Address At Point Of Arrival] " & _
                                             " FROM plane ORDER by txtstdid", cnn)

        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        Me.dgvData.DataSource = dt

        'close connection
        cnn.Close()
    End Sub

Recommended Answers

All 3 Replies

First of all, never use blanks in the name of a field. You should use "Date_of_Birth" rather than "Date of Birth".

Secondly, you are retrieving three different fields (chodob1, chodob2 and chodob3) and giving them the same alias (Date Of Birth). Same problem with "Date Of Departure". Fix that and see what happens.

something like this?

Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            'open connection
            cnn.Open()
        End If
 
        Dim da As New OleDb.OleDbDataAdapter("SELECT txtstdid as [ID], " & _
                                             "txtstdname as [Name], cbosex as [Gender], chodob1 as [Date], chodob2 as [Month], chodob3 as [Year], txtic as [Identification Number Card], txtpassn as [Passport Number], txtpn as [Phone Number], dod1 as [Date], dod2 as [Month], dod3 as [Year], txtaddress as [Address], txtaapoa [Address At Point Of Arrival] " & _
                                             " FROM plane ORDER by txtstdid", cnn)
 
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)
 
        'offer data in data table into datagridview
        Me.dgvData.DataSource = dt
 
        'close connection
        cnn.Close()
    End Sub

Still won't work. You are using Date, Month and Year twice each. The easiest way to debug queries is to download and install SQL Management Studio (free from Microsoft). This allows you to run interactive queries against database tables (among many other things). Once you have the query working in the console you can translate it into code.

And you are still using blanks in the field names. Not a good idea. You should either remove them or replace them with underscores.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.