Fill error in dataset

L

Lasse Edsvik

Hello

I get the following error:

Fill: SelectCommand.Connection property has not been initialized.

what's wrong? connection works but it refuses to fill the dataset.


using System.Data;

using System.Data.OleDb;

/*

CODE.......

*/

OleDbConnection conn = new OleDbConnection();

conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db.mdb";


try

{

conn.Open();

OleDbDataAdapter DA = new OleDbDataAdapter();

OleDbCommand SQL = new OleDbCommand("SELECT * FROM Products");

DataSet DS = new DataSet();

DA.SelectCommand = SQL;


DA.Fill(DS,"Products");


}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

finally

{

conn.Close();

}
 
J

Jon Skeet [C# MVP]

Lasse Edsvik said:
Fill: SelectCommand.Connection property has not been initialized.

what's wrong? connection works but it refuses to fill the dataset.

As it says, the connection property of the select command hasn't been
set. You've opened a connection, but not told anything to use it. If
you put:

SQL.Connection = conn;

after you construct your command, it works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top