Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:20:31+00:00 2026-06-13T13:20:31+00:00

Possible Duplicate: Issue with displaying SQL result in DataGridView I’ve kind of asked this

  • 0

Possible Duplicate:
Issue with displaying SQL result in DataGridView

I’ve kind of asked this question before but never got it sorted. Basically I am trying to populate a datagridview on my form with the results of an SQL query. I get no errors from this code but I do just get a completely blank datagridview i.e it does not show a thing, not even the column headings.

Also please note I know im currently open to SQL injection on my sql, I just want to get this working before I sort that.

Here is my whole class code:

Imports System.Data.OleDb
Imports System.Data

Public class TechScreen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0: Data Source = C:\Users\Dave\Documents\jobList.mdb;")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM jobList WHERE techID = " &  TechScreenID &"", con)
con.Open()
Dim DA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim mydataset As DataSet = New DataSet
DA.Fill(mydataset, "MyTable")
DataGridView1.DatSource = mydataset.Tables("MyTable").DefaultView
con.Close()
con = Nothing

End sub
End class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:20:32+00:00Added an answer on June 13, 2026 at 1:20 pm

    First off, while it may or may not be the source of your problem, the line:

    DataGridView1.DatSource = mydataset.Tables("MyTable").DefaultView
    

    Contains a typo. Should be DataGridView1.DataSource. Seems like this would have caused a compiler error though.

    Other than that, try simplifying things similar to the below, and if you still have the binding problem, step through in the debugger to make sure everything is working as expected. Also, check that the “Autogenerate Columns” property on your dgv control is set to true.

    I am not clear on some of what you are trying to do, so the following is a very general example of how I would approach this.

    • First off, move your connection string to the project settings file,
      and use My.Settings.MyConnectionStringName to refer to it.
    • Second, use Parameters in your SQL, instead of in-line concatenation.
    • Wrap your data access stuff in “Using” Blocks. Using will handle
      disposal of objects within the blocks scope for you, and is generally
      a cleaner way to go.
    • Just my personal preference, but I don’t like all the bs overhead
      that comes with Data Sets which a simple data table will do.
    • I didn’t do it here as fully as possible here, but I recommend
      separating the data retrieval from assignment to a UI control. Even
      more, I would probably go the next step, and separate the control
      assignment from the Form Load event as well. You may well find that
      there are multiple places in your form which require the datasource
      to refresh or reset.

    There are a variety of ways to approach this, and mine is not necessarily the “popular way. However, the following worked for me just now.

    Simplify your code, and employ some refactoring:

    Imports System.Data
    Imports System.Data.OleDb
    
    Public Class TechScreen
    
        Private Sub TechScreen_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
            'Not sure where your TechScreenID input parameter is coming from, so this is just for example:
            Dim TechID As Integer = 1
    
            ' Use a function to return the data to be used as the DataSource for the dgv control:
            DataGridView1.DataSource = Me.JobListTable(TechID)
    
        End Sub
    
    
        Private Function JobListTable(TechID As Integer) As DataTable
            Dim dt As DataTable = Nothing
    
            Dim SQL As String = "SELECT * FROM joblist WHERE techID = @TechID"
    
            ' The Using block handles disposal of objects initialized:
            Using con As OleDbConnection = New OleDbConnection(My.Settings.MyConnection)
                Using cmd As OleDbCommand = New OleDbCommand(SQL, con)
    
                    ' Use parameters instead of inline concatenation for cleaner code,
                    ' and protection against sql injection attacks:
                    cmd.Parameters.AddWithValue("@TechID", TechID)
                    con.Open()
    
                    dt = New DataTable()
    
                    Try
                        dt.Load(cmd.ExecuteReader())
                    Catch
                        MsgBox("There was an error retrieving data")
                    Finally
                        con.Close()
                    End Try
                End Using
            End Using
    
            Return dt
    
        End Function
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Gesture detection and ScrollView issue EDIT: question with full code asked here
Possible Duplicate: PHP: Opening/closing tags & performance? this is probably a stupid question, but
Possible Duplicate: Android Layout and positioning issue Design layout which support for all kind
Possible Duplicate: Floating point inaccuracy examples PHP rounding issue - Is this a bug?
Possible Duplicate: How do I get this CSS text-decoration issue to work? I'm using
Possible Duplicate: Visual Studio 2005 doesn't support Sql Server 2008 I've got an issue
Possible Duplicate: Browser Independence issue Code Working for IE but not for Firefox and
Possible Duplicate: Is JavaScript's Math broken? I came across this rounding issue: When I
Possible Duplicate: Javascript for loop and setTimeout issue I want this loop to change
Possible Duplicate: Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) Hey I have seen this issue a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.