Fill error in dataset

  • Thread starter Thread starter Lasse Edsvik
  • Start date Start date
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();

}
 
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.
 
Back
Top