DataAdapter select assuming integer

T

tshad

How do I tell DataAdapter that Column 2 and 3 are string and not integer?
Following is the example data that comes from the .csv file

FEDERAL TAX,1084,0000
COREHCR,1084,0000
CLIENT P,1084,0000

The select is:

OleDbDataAdapter da2 As New OleDb.OleDbDataAdapter("Select * from " &
"CorelandGLConversion.csv", conn);

The problem is that it thinks the 3rd column is an integer and changes the
0000 to 0.

Can I tell it in the Select statement that the column is a varChar? I can't
do it after reading in the data as the data will already have changed the
0000 to 0 at that point.

Thanks,

Tom.
 
T

tshad

tshad said:
How do I tell DataAdapter that Column 2 and 3 are string and not integer?
Following is the example data that comes from the .csv file

FEDERAL TAX,1084,0000
COREHCR,1084,0000
CLIENT P,1084,0000

The select is:

OleDbDataAdapter da2 As New OleDb.OleDbDataAdapter("Select * from " &
"CorelandGLConversion.csv", conn);

The problem is that it thinks the 3rd column is an integer and changes the
0000 to 0.

Can I tell it in the Select statement that the column is a varChar? I
can't do it after reading in the data as the data will already have
changed the 0000 to 0 at that point.

I tried to set up the table as:

DataTable DTGLConversion as DataTable;

DTGLConversion.Columns.Add("F1", System.Type.GetType("System.String"));
DTGLConversion.Columns.Add("F2", System.Type.GetType("System.String"));
DTGLConversion.Columns.Add("F3", System.Type.GetType("System.String"));

da2.Fill(DTGLConversion);
DataSetObj.Tables.Add(DTGLConversion);

This sets up the columns as strings in the DTGLConversion Table and adds it
to the Dataset but it seems the Select in the DataAdapter must have already
converted the string "0000" to integer 0 and then when I filled the
DataTable it reconverted it to "0".

How do I fix this?

Thanks,

Tom
 
B

bob

Hi Tom,
If you do a ' manual read' with a datareader
do you get a string?
something like
cmdSource = cmdConn.ExecuteReader(CommandBehavior.CloseConnection);
if ((cmdSource.Read() == true))
{
sResult = cmdSource.GetString(2);
If this gives a string of "0" I would say your only hope is to do a
file read.
hth
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top