data won't populate, what am I missing? (1 Viewer)

joe789

Registered User.
Local time
Today, 14:30
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I wrote this code below that renders no error when ran; however, it does nothing. Ideally, I would like the code to display the data in the table on the form ... I don't get what I am missing. I am just starting out trying to create database apps in visual studios .net 2010 using sql server as a back end and vb code as front end ... any help would be greatly appreciated.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml

Public Class Form1
Private m_CB As SqlCommandBuilder
Private m_DataTable As New DataTable
Private m_cn As New SqlConnection()
Private m_rowposition As Integer = 0
Private m_da As New SqlDataAdapter
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
m_cn.ConnectionString = "Data Source=SQLDATA;User ID=HEKTOR;Password=RYANZ;"
m_cn.Open()
m_da = New SqlDataAdapter("select * from [HU]", m_cn)
m_CB = New SqlCommandBuilder(m_da)

m_da.Fill(m_DataTable)

End Sub
End Class
 

dan-cat

Registered User.
Local time
Today, 14:30
Joined
Jun 2, 2002
Messages
3,433
What you have there is code to populate a datatable with your query.

But you won't view any data on your form until you bind that datatable to a control, a datagridview for example, on your form.

Examples of how to do this can be found here link

You're most of the way there, you just need to complete the final step

...

Code:
Me.dataGridView1.DataSource = Me.bindingSource1
Me.bindingSource1.DataSource = m_Table
 

Users who are viewing this thread

Top Bottom