OleDBCommand does not contain a definition for 'Fill'?

B

Brian

Was browsing around online for code to connect to a database usign ADO
and C#... and i found this very simple but useful reference
(http://www.c-sharpcorner.com/database/db_list.asp)

However, implementing this into my own project does seem to work.

I'm getting an error: 'System.Data.OleDb.OleDbCommand' does not
contain a definition for 'Fill'

Why would this be?

PS - code below for reference.

private void Form1_Load(object sender, System.EventArgs e)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=photoDB.MDB";
string strSQL = "SELECT * FROM photos" ;

// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, myConn );

myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "photos" );
DataTable dTable = dtSet.Tables[0];

foreach( DataRow dtRow in dTable.Rows )
{
listBox1.Items.Add( dtRow["Name"].ToString());
listBox1.Items.Add( dtRow["Address"].ToString());
}
 
G

Guest

Brian,

This is because the OleDbCommand does not have a method of Fill. If you
look at the example again (that you posted) you will see that they are using
an OleDbDataAdapter not an OleDbCommand object. I have provided a sample
below for you.

Hope this helps.
 

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

Top