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:

Dim 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:

Dim 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:

Dim 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
 
G

Guest

I tried to set up the table as:

Dim 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- Hide quoted text -

- Show quoted text -

Try to use schema.ini file

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp

I think it should be similar to this

[CorelandGLConversion.csv]
Format=Delimited(;)
ColNameHeader=True
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char

and place that file in the same folder as the CSV file
 
T

tshad

Anon User said:
I tried to set up the table as:

Dim 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- Hide quoted text -

- Show quoted text -

Try to use schema.ini file

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp

I think it should be similar to this

[CorelandGLConversion.csv]
Format=Delimited(;)
ColNameHeader=True
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char

and place that file in the same folder as the CSV file

It almost works. It does give me everything. But it doesn't split each
line into 3 columns.

It makes each line one columns and ignores the comma separators. If I
change the name of the file in the schema file (so that it doesn't use it),
it splits each line (row) into 3 columns.

column 1 = FEDERAL TAX,1084,0000
column 2 = Null
column 3 = Null

If I leave out the schema.ini file (or just change the file name in the
file), I get:

column 1 = FEDERAL TAX
column 2 = 1084
column 3 = 0

Thanks,

Tom
 
T

tshad

Found it.

I needed to have:

Format=CSVDelimited

in my file.

Thanks,

Tom
tshad said:
Anon User 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:

Dim 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:

Dim 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- Hide quoted text -

- Show quoted text -

Try to use schema.ini file

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp

I think it should be similar to this

[CorelandGLConversion.csv]
Format=Delimited(;)
ColNameHeader=True
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char

and place that file in the same folder as the CSV file

It almost works. It does give me everything. But it doesn't split each
line into 3 columns.

It makes each line one columns and ignores the comma separators. If I
change the name of the file in the schema file (so that it doesn't use
it), it splits each line (row) into 3 columns.

column 1 = FEDERAL TAX,1084,0000
column 2 = Null
column 3 = Null

If I leave out the schema.ini file (or just change the file name in the
file), I get:

column 1 = FEDERAL TAX
column 2 = 1084
column 3 = 0

Thanks,

Tom
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top