473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CSV to DataSet does not respect empty strings

using vs 2003
the csv file has every field value enclosed in double quotes: i.e. no null
values

Whe using OleDbDataAdapter to read a csv file (I do create the schema.ini
file defining all columns as text) into a DataTable, fields that are an empty
string ("") are set to DBNull in my data table. I need to serialize this
dataset to an xml file and the lack of an empty node for all fields is a
problem.

Any solutions?

a short program follows

*****test.csv*****
FirstName,LastName,Sex
"kevin","williams","m"
"bob","le flambeur",""
*****test.csv*****

****schema.ini****
[test.csv]
ColNameHeader=True
Format=CSVDelimited
MaxScanRows=0
CharacterSet=OEM
Col1=FIRSTNAME TEXT
Col2=LASTNAME TEXT
Col3=SEX TEXT
****schema.ini****

****class1.cs****
class class1
{
[MTAThread]
static void Main(string[] args)
{

string constring = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\mmproc\\;Extended
Properties=\"text;HDR=Yes;FMT=Delimited;IMAX=1\"";

DataSet ds = new DataSet("MyDataSet");
ds.Tables.Add(new DataTable("MyTable"));
DataTable dt = ds.Tables[0];

dt.Columns.Add("FirstName",typeof(string));
dt.Columns.Add("LastName", typeof(string));
DataColumn sexCol = dt.Columns.Add("Sex",typeof(string));
sexCol.DefaultValue = "";

OleDbCommand cmd = new OleDbCommand("select * from [test.csv]");
cmd.Connection = new OleDbConnection(constring);
cmd.CommandType = CommandType.Text;
OleDbDataAdapter adp= new OleDbDataAdapter();

using(OleDbConnection con = cmd.Connection)
{
con.Open();
adp.SelectCommand = cmd;
adp.Fill(dt);
}
ds.WriteXml("c:\\mmproc\\kevinDataset.xml");
}// main
}
****class1.cs****

****kevinDataset.xml****
<?xml version="1.0" standalone="yes"?>
<MyDataSet>
<MyTable>
<FirstName>kevin</FirstName>
<LastName>williams</LastName>
<Sex>m</Sex>
</MyTable>
<MyTable>
<FirstName>bob</FirstName>
<LastName>le flambeur</LastName>
</MyTable>
</MyDataSet>
****kevinDataset.xml****
--
kevin...
Jun 22 '06 #1
0 1477

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
2
by: Iwan Petrow | last post by:
Hi, I have two tables with relation: Table1: T1_id T2_id (foreign key,allow null) ..... Table2
7
by: David | last post by:
Hi, using C# asp.net 1.1 I am having a problem. If I use the code below, but have null passed as the PostingGuid, then by the time I get to fill the dataset, I have "an object is not set to...
21
by: Ray Cassick | last post by:
I can't believe why I had not noticed this before and why I never asked it before... When defining a string why is it not required to use the new keyword? Like: Dim a As String = New String ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.