none
How to access table in mdl file? RRS feed

  • Question

  •  

    Hi,

     

    I try to access Links table in ImgLinks.mdl database using the followinf code:

     

    OleDbDataAdapter adapter = new OleDbDataAdapter();

    DataSet imgLinksDS = new DataSet();

    OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\ImgLinks.mdb");

    OleDbCommand aCommand = new OleDbCommand("select * from Links", aConnection);

    adapter.SelectCommand = aCommand;

    OleDbCommandBuilder MyBuilder = new OleDbCommandBuilder(adapter);

    adapter.Fill(imgLinksDS);

     

    but there is no Links table in imgLinksDS and i get NullReferenceException at the line :

     

    DataRow row=imgLinksDS.Tables["Links"].NewRow();

     

    Thanx :-)

    Monday, December 10, 2007 12:30 PM

All replies

  • Hi,

    It seems something wrong with your codes for using of OleDbCommand. I notice your code is using disconnection layer ,so there is no need to define an OleDbCommand object 'aCommand'. you can change your code as follow that should work for you.

    Code Snippet

    OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\ImgLinks.mdb");

     

    OleDbDataAdapter adapter = new OleDbDataAdapter("select * from Links", aConnection);

     

    DataSet imgLinksDS = new DataSet();

     

    OleDbCommandBuilder MyBuilder = new OleDbCommandBuilder(adapter);

    adapter.Fill(imgLinksDS);

     

    Regards

    Jing

    Wednesday, June 11, 2008 8:20 AM