0

I have a project VS 2008 SmartDevice Application. There DBFile is created and my dbFile name is .DBFile.sdf with 3 tables. I need to update the table with values of another table in sql server 2014. I used XML File to load the table.

XML File Code : D:/Import.XML *

<?xml version='1.0'?>
<Items>
 <Item> 
    <CustCode>G0014</CustCode>
    <InDocketRef>030073</InDocketRef>   
    <ImportDate>2023-01-10T00:00:00</ImportDate>    
    <UniqueCode>8888</UniqueCode>
    <unit>CTN</unit>
  </Item>
  <Item>
    <CustCode>G0014</CustCode>
    <InDocketRef>030073</InDocketRef>   
    <ImportDate>2023-01-10T00:00:00</ImportDate>   
    <UniqueCode></UniqueCode>
    <unit></unit>
  </Item></Items>

in my .cs file i used the below code:

DataSet ds = new DataSet();
  ds.ReadXml(@"D:\Import.XML");
  DataTable table = new DataTable();
  table = ds.Tables[0];
  dataGrid1.DataSource = table;

but it throws the error:

Could not find a part of a path. But the path is correct.

Anyone please help to fix this issue? please suggest if there is any better way to connect with Sql server 2014 to retrieve the data.

Thom A
  • 88,727
  • 11
  • 45
  • 75
Belinda
  • 116
  • 13
  • You have a compact SQL database (SDF). A SQL Server is a MDF file. See following to connected to SDF: https://www.connectionstrings.com/sql-server-compact/ – jdweng May 03 '23 at 09:51
  • If I run that code, it works. *But the path is correct* that might be so, the File System can't find the file there. Move it to a subfolder instead of the root of the drive in case some virus scanner goes bezirk on file access in that location. Create a fresh folder, move the file there and adapt the filepath in your ReadXML accordingly – rene May 03 '23 at 10:00
  • Hi @rene i have created one .xml file within the project. that is also not working. @"MYHP01\D:\WHPDT\WHPDT\PackListImport.xml" this is my path to the file. the same error is coming. – Belinda May 03 '23 at 10:24
  • when i use the below code, StringReader xmlDoc = new StringReader(@"D:\Import1.xml"); ds.ReadXml(xmlDoc); getting "Data at the root level is invalid. Line 1, position 1." at the second line – Belinda May 03 '23 at 10:26
  • But *Data at the root level is invalid. Line 1, position 1* is a different exception and that doesn't match the example xml then because the example in your question works, aka is valid XML and results in a populated datatable. We can't resolve an issue if your local situation isn't replicated in your question. Please [edit] your question with an XML and working code hat produces for you the exact same exception as you have in your actual project. – rene May 03 '23 at 10:32
  • wrt `@"MYHP01\D:\WHPDT\WHPDT\PackListImport.xml` ... are you trying to read that file from a server? If yes, then don't., and if you really have to, use `@"\\MYHP01\D:\WHPDT\WHPDT\PackListImport.xml` but try that first in a windows explorer to see if the path even works. – rene May 03 '23 at 10:34
  • Thank you for your reply @rene. I am not using server. was trying with my device name as suggested by different site and that is also not working. – Belinda May 03 '23 at 11:16

0 Answers0