Answers

May 22, 2007 - 09:17 AM

May 22, 2007 - 10:31 PM
Here is an example that uses MSAccess as its database
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\mydb.mdb")
Dim adapter As New OleDbDataAdapter("SELECT Field1, Field2 FROM MyTable", conn)
Dim dt As New DataTable("MyTable")
adapter.Fill(dt)
DataGrid1.DataSource = dt
the above reads the table MyTable and populates the data grid (control is called DataGrid1) with the fields Field1 and Field2

Jun 01, 2009 - 01:14 AM
http://www.programmersheaven.com/mb/V...

Jun 24, 2010 - 02:58 AM
Below is code sample to populated data in datagridview
here is DGVData is gridview name
Public Class Form1
Private Const ConnectionString As String = "Server=Severname;" & _
"Database=DatabeaseName;UID='sa';PWD=''"
Private ReadOnly Property Connection() As SqlConnection
Get
Dim ConnectionToFetch As New SqlConnection(ConnectionString)
ConnectionToFetch.Open()
Return ConnectionToFetch
End Get
End Property
Public Function GetData() As DataView
Dim SelectQry = "SELECT * FROM PaymentMode "
Dim SampleSource As New DataSet
Dim TableView As DataView
Try
Dim SampleCommand As New SqlCommand()
Dim SampleDataAdapter = New SqlDataAdapter()
SampleCommand.CommandText = SelectQry
SampleCommand.Connection = Connection
SampleDataAdapter.SelectCommand = SampleCommand
SampleDataAdapter.Fill(SampleSource)
TableView = SampleSource.Tables(0).DefaultView
Catch ex As Exception
Throw ex
End Try
Return TableView
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DGVData.DataSource = GetData()
End Sub

Sep 25, 2011 - 11:55 PM

Sep 25, 2011 - 11:57 PM
Add New Comment