Data not being displayed correctly on datagridview

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 117
Reputation: kavithabhaskar is an unknown quantity at this point 
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Data not being displayed correctly on datagridview

 
0
  #1
Jul 31st, 2008
when i click "button1" on my form..i get field name as ' Expr1002' and the data in it are -1..

i believe it is soemthing to do with the da.fill() .. can u please asssist me with thsi ?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")

Dim cmd As New OleDbCommand

con.Open()

cmd = New OleDbCommand("select MFG, MAKE, GRAPHICSCARD AND GRAPHICSVERSION from table1", con)

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Try

Dim ds As DataSet = New DataSet()

ds.Tables.Add("table1")

da.Fill(ds, "table1")

DataGridView1.DataSource = ds.Tables("table1").DefaultView

Finally

con.Close()

cmd = Nothing

da.Dispose()

con.Dispose()

End Try

End Sub
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1
Reputation: akwadkar is an unknown quantity at this point 
Solved Threads: 0
akwadkar akwadkar is offline Offline
Newbie Poster

Re: Data not being displayed correctly on datagridview

 
0
  #2
Aug 6th, 2008
Corrected Code Please Check


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")

Dim cmd As New OleDbCommand
Dim ds As DataSet = New DataSet()
con.Open()
cmd = New OleDbCommand("select MFG, MAKE, GRAPHICSCARD AND GRAPHICSVERSION from table1", con)

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
da.fill(ds,"table1")


Try

'ds.Tables.Add("table1")
'da.Fill(ds, "table1")
'DataGridView1.DataSource = ds.Tables("table1").DefaultView

dataGridview1.datasource = ds
datagridview1.datamember = "table1"

Finally

con.Close()

cmd = Nothing

da.Dispose()

con.Dispose()

End Try

End Sub
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1
Reputation: kris_2_christ is an unknown quantity at this point 
Solved Threads: 0
kris_2_christ's Avatar
kris_2_christ kris_2_christ is offline Offline
Newbie Poster

Re: Data not being displayed correctly on datagridview

 
0
  #3
Aug 6th, 2008
Try to bind the datagrid
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum


Views: 682 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC