I'm trying to insert data into a csv file using System.Data.OleDb but
I'm unable to insert rows with character fields bigger that 255
characters.

the code:

const String INSERT_STATEMENT = "insert into [table#csv] (SmallStr,
BigStr) values (@SmallStr, @BigStr)";
OleDbConnection oConn = new
OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\\db\
\;Extended Properties=\"text;HDR=YES;\"");
oConn.Open();
OleDbCommand oCmd = new OleDbCommand(INSERT_STATEMENT,
oConn);

OleDbParameter oParam = null;
oParam = new OleDbParameter("SmallStr", OleDbType.VarChar,
255);
oParam.Value = "0123456789";
oCmd.Parameters.Add(oParam);
oParam = new OleDbParameter("BigStr",
OleDbType.LongVarChar, 1024);
oParam.Value =
"012345678901234567890123456789012345678901234567890123456789012345"+

"678901234567890123456789012345678901234567890123456789012345678901234567890123"+

"456789012345678901234567890123456789012345678901234567890123456789012345678901"+
"23456789012345678901234567890123456789"; //260
characters
oCmd.Parameters.Add(oParam);

oCmd.ExecuteNonQuery();


The above does work if i change the BigStr param to 255 chars or less.
I've tried playing around with putting status.ini files into the
folder in various configurations but nothing seems to help.
I'm hoping though that it is possible to get more than 255 characters
into a text file using OleDb and Jet.

If anyone could help me with this I would be very greatful, spent ages
trying to get it right.

Thanks in advance :-)

Re: Inserting into csv files using Jet and System.Data.OleDb by cameron

cameron
Thu Apr 24 11:15:25 CDT 2008

oh yes, the error message I'm getting is OleDbException "The field is
too small to accept the amount of data you attempted to add. Try
inserting or pasting less data."

Re: Inserting into csv files using Jet and System.Data.OleDb by Paul

Paul
Tue Apr 29 10:30:36 CDT 2008

On Thu, 24 Apr 2008 09:15:25 -0700 (PDT), cameron.waldron@gmail.com wrote:

¤ oh yes, the error message I'm getting is OleDbException "The field is
¤ too small to accept the amount of data you attempted to add. Try
¤ inserting or pasting less data."

Are you importing into an existing table or creating a new table from the import? You may want to
post your code.

Basically, the error indicates that the column that is receiving the data hasn't been defined to be
large enough to accept the data you're trying to save to it (from the text file).


Paul
~~~~
Microsoft MVP (Visual Basic)