Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello!

 

I have this code :

 

Dim myConnection As New OleDb.OleDbConnection

Dim myCommand As New OleDb.OleDbCommand

Dim myReader As OleDb.OleDbDataReader

Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=C:\Database.mdb"

 

myConnection = New OleDb.OleDbConnection(myConnectionString)

myConnection.Open()

 

Dim mySelect As String = "SELECT name, birthdate FROM MyTable"

myCommand = New Oledb.OleDbCommand(mySelect, myConnection)

myReader = myCommand.ExecuteReader()

End Sub

 

I want my datagrid to show the names and birthdates when I press on button1. How do I do that?

(as you have already guessed, I'm a beginner so if you know the easiest way...) :confused:

Posted

do you have a data adapter created, either do it at design time or programmatically. Either way, you need to create a data adapter, then from that generate a dataset. Bind the dataset to the datagrid.

 

Try this:

dim mydataset as new dataset

oledbdataadpater1.fill(mydataset)

datagrid.setdatabinding(mydataset, "MyTable")

 

Hope this helps.

Posted

create oledbdataadapter as

 

Dim oledb_adap ad OleDb.OleDbDataAdapter

oledb_adap.selectcommand.commandtext="Select name, birthdate FROM MyTable"

 

Dim data_set as New DataSet()

 

oledb_adap.fill(data_set)

datagrid1.setdatabinding(data_set,"mytable")

Rufus
Posted

Rufus I've pasted your code and there seem to be a problem with the line :

 

oledb_adap.selectcommand.commandtext="Select name, birthdate FROM MyTable"

 

I've never created dataAdapter or dataSet before, so maybe that you've omitted a line that seems obvious to you... but not to me!

Posted

Well, I've tried this code :

 

Dim myConnection As New OleDb.OleDbConnection

Dim myCommand As New OleDb.OleDbCommand

Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=C:\Database.mdb"

 

myConnection = New OleDb.OleDbConnection(myConnectionString)

myConnection.Open()

 

Dim mySelect As String = "SELECT name, birthdate FROM MyTable"

myCommand = New OleDb.OleDbCommand(mySelect, myConnection)

 

Dim oledb_adap As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

oledb_adap.SelectCommand = myCommand

 

Dim data_set As DataSet = New DataSet

oledb_adap.Fill(data_set)

DataGrid1.SetDataBinding(data_set, "MyTable")

 

It works...except for the last line, the datagrid filling, which is where an error occurs...

There is an "unhandled exception",

The message says (I'm translating from french so i don't know if it is right) "Impossible to create a child list (?) for the field MyTable"

 

Please help!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...