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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.