Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Closed Points: 25 Time: 08:01 - May 21, 2007  

hugh

how to populate the datagridview in vb.net 2.0

how to populate the datagridview in vb.net 2.0

Categories

Answer Discussion
Tutorials

 

nidhi

Date:: May 22, 2007

Time:: 12:17

Here is a C# example http://www.codeproject.com/useritems/Dat...
it can easily be adapted to vb.net

nidhi

Date:: May 23, 2007

Time:: 01:31

Wot database do you have?
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

admin

Date:: Jul 02, 2007

Time:: 09:55

hugh, please close this question and distribute the points.
If you didn't get a solution to your problem or you found it yourself, please leave a comment here to let the experts know.
Thanks,
Quomon Admin

admin

Date:: Aug 17, 2007

Time:: 11:54

The question has been closed.

The Quomon Admin Team

vbnetmayor

Date:: Jun 01, 2009

Time:: 04:14

Here is an example
http://www.programmersheaven.com/mb/VBNE...

Question Answered

This question has been closed, and points have been rewarded to the following experts:


nidhi: 25

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

awdheshgupta

Date:: Jun 24, 2010

Time:: 05:58


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


Click here to see the Answer Discussion that preceded this tutorial.


Login to rate this tutorial: Good  |  Bad

liamweb

Date:: Sep 26, 2011

Time:: 02:55

some more datagridview tutorial here

http://vb.net-informations.com/datagridv...

liam


Click here to see the Answer Discussion that preceded this tutorial.


Login to rate this tutorial: Good  |  Bad

liamweb

Date:: Sep 26, 2011

Time:: 02:57

datagridview tutorial

http://vb.net-informations.com/datagridv...

liam


Click here to see the Answer Discussion that preceded this tutorial.


Login to rate this tutorial: Good  |  Bad

bidyotdas

Date:: Oct 23, 2011

Time:: 14:39


Please can any one suggest me why i am failed to populate my
datagridview here. i dont know where i hv done mistake.
I am stuck here
<code>
If mConnection Is Nothing Then mConnection = New Odbc.OdbcConnection
' check if the connection is already open
If mConnection.State = ConnectionState.Open Then mConnection.Close()
' open the connection to the database
' string to store the connection string
Dim connectionstring As String
Dim username As String = "root" 'CHANGE THIS
Dim password As String = "root" 'CHANGE THIS
Dim server As String '"localhost" or "127.0.0.1" or "192.164.215.243" or "www.google.com" or "www.palomasoaps.com" or "Bill.apollo.net"
Dim driver As String = "{MySQL ODBC 5.1 Driver}"
Dim database As String = "studentproject"
' the connection string object
server = "localhost"
connectionstring = "Driver=" & driver & "; Server=" & server & "; User=" & username & "; Password=" & password & ";Database=" & database & ";"
' try to open the connection
mConnection.ConnectionString = connectionstring
Try
mConnection.Open()



Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
' check the state to see if it opened correctly
If mConnection.State <> ConnectionState.Open Then
MessageBox.Show("Error Opening Connection")
ElseIf mConnection.State = ConnectionState.Open Then

Dim dataView As New DataGridView()
Try
Dim sqlCommand As New Odbc.OdbcCommand

Dim ds As Odbc.OdbcDataAdapter
sqlCommand.Connection = mConnection
sqlCommand.CommandText = "select * from messages"
ds = New Odbc.OdbcDataAdapter(sqlCommand.CommandText, mConnection)


Dim dataSet As DataSet = New DataSet
ds.Fill(dataSet, "messages")
dataSet.WriteXml("C:\\OutputXML.xml")
Dim dgvRow As DataGridViewRow

For Each dgvRow In dataView.SelectedRows
Debug.Print(dgvRow.Cells(0).Value)
Next

Me.dataView.DataSource = dataSet.Tables("messages")



Catch ex As Exception
MessageBox.Show(ex.ToString)
MsgBox("Something went wrong..")
End Try
</code>


Click here to see the Answer Discussion that preceded this tutorial.


Login to rate this tutorial: Good  |  Bad

rumeshchanchal

Date:: Jan 05, 2012

Time:: 06:22

Very informative post. It's really helpful for me and helped me lot to complete my task. Thanks for sharing with us. I had found another nice post over the internet which was also explained very well about Populate Grid Control From XML Document Easily, for more details of this post check out this link...

http://mindstick.com/Articles/6c3ccf8c-6...20Grid%20Control%20From%20XML%20Document%20Easily

Thanks Everyone!!


Click here to see the Answer Discussion that preceded this tutorial.


Login to rate this tutorial: Good  |  Bad

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es