View Full Version : data won't populate, what am I missing?


joe789
06-23-2011, 09:56 AM
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
06-23-2011, 12:07 PM
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 (http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx)

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

...

Me.dataGridView1.DataSource = Me.bindingSource1
Me.bindingSource1.DataSource = m_Table