Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADON.NET oleDbException

Status
Not open for further replies.

bartekR

Technical User
Aug 18, 2007
24
0
0
GB
Hi All

I am just starting learning C# and trying to do a simple excercise :

I have an Acess database from which I would like to extract all data from one table and write it to the XML file.

This is my code :
----------------------------------------------------------
1. Load a default file path int the textbox (txtFilePath) on the form :

private void Form1_Load(object sender, EventArgs e)
{
txtFilePath.Text=@"C:\Users\Acer User\Documents\Access Development\TestDbase.mdb";
}

-----------------------------------------------------------

2. Extract all data from Gilts_Details Access table and write to xml file

private void btnXML_Click(object sender, EventArgs e)
{
//access data source
string sCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + txtFilePath;

OleDbConnection myConnection = new OleDbConnection(sCon);

//SQL COMMAND
string sSql = "SELECT * FROM [Gilts_Details]";

//CONNECT
OleDbDataAdapter myAdapter= new OleDbDataAdapter(sSql, myConnection);

//RETRIEVE DATA
DataSet myQueryData = new DataSet();
myAdapter.Fill( myQueryData);

//RETURN DATA TO XML FILE

string sXMLPath=@"C:\Users\Acer User\Documents\Visual Studio 2005\Projects\TestADO\TestADO\XmlFile.xml";

myQueryData.WriteXml(sXMLPath);

When i run this i get an oledbException error in that line :
myAdapter.Fill( myQueryData); with a comment "not a valid file name".

I have double checked and all the paths are correct.

Can anyone help?

Thank you
 
Try changing
Code:
string sCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + txtFilePath;

to
Code:
string path = txtFilePath;
string sCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + txtFilePath.Text
Assuming txtFilePath is a TextBox?
does that work?

Age is a consequence of experience
 
sorry! The lines:
Code:
string path = txtFilePath;
string sCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + txtFilePath.Text
should just be
Code:
string sCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " + txtFilePath.Text


Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top