hobbes2103 Posted July 16, 2003 Posted July 16, 2003 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: Quote
Smithbr Posted July 16, 2003 Posted July 16, 2003 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. Quote
rufus Posted July 17, 2003 Posted July 17, 2003 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") Quote Rufus
hobbes2103 Posted July 17, 2003 Author Posted July 17, 2003 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! Quote
hobbes2103 Posted July 17, 2003 Author Posted July 17, 2003 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!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.