Problem with format of xml file created from dataset

HI

I have a connection to excel that retrieves data to a dataset.

Its working fine, my problem is organizing the data so that I can record it to the data base.

I’m trying to do it by converting the data to xml, so that I can ask the user to relate the column name (in the excel file) with the correct place in the database.

And parse to the retrieved data.

The code so far is:

Dim cnAs System.Data.OleDb.OleDbConnection

Dim cmdAs System.Data.OleDb.OleDbDataAdapter

Dim dsAsNew System.Data.DataSet()

cn =New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _

"data source=C:\2.XLS;Extended Properties=Excel 8.0;")

' Select the data from Sheet1 of the workbook.

cmd =New System.Data.OleDb.OleDbDataAdapter("select * from [cli$]", cn)

cn.Open()

cmd.Fill(ds)

ds.WriteXml("C:cli.xml")

Im hard coding, so that i can analise the xml file.

My problem is some excel files load to the dataset ok, but creates _x0020 after the name of the column: this one is supposed to appear like <NOME>

<Nome_x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020__x0020_>

So as the data in the dataset is all the same im wondering if the problem is on the creation of the xml. It is strange because some excel files don’t have any problem.

Any ideas?

Thanks

[6067 byte] By [BarataMota] at [2007-12-26]
# 1

Hi,

Here is a link about why appear x0020: http://msdn2.microsoft.com/en-us/library/xfaz0c52(VS.80).aspx

It seems writexml method write some blankspace for you, if it is possible to truncate blank before write to xml like:

ds.DataTable(0).TableName = dataset.DataTable(0).TableName.Trim()

regards

tangfx at 2007-9-4 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified