number of columns

A

atse

Hi,

How can I know the number of columns of the .csv files? I want to import
them to the database.
Thanks.

Atse
 
D

Dan Brussee

Can you tell me more detail? Any sample? Thanks.

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)
 
A

atse

How can I know the number of columns of the .csv files? I want to
s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)

Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know how to
select [what] from thisfile.csv so that I can get a string with commas:-(
 
D

Dan Brussee

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)

Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know how to
select [what] from thisfile.csv so that I can get a string with commas:-(

Why do you need to have this? Once you have split a line of text into
an array, you will have the VALUES for an INSERT statement.

"INSERT INTO Tbl (cola, colb, colc...) VALUES (" & a(0) & "," & .....

Alternatively, if you are looking to open the CSV file with an ADO
type command, you will nee to find the appropriate connection string,
then issue a statement like...

"SELECT * FROM File.csv" (or something like that).

From the recordset that this yields, you can look at the fields
collection. They will not have a "name" per se, but you can get a
count and cycle through them by number...

rs.fields(0)
 
A

atse

Dan Brussee said:
How can I know the number of columns of the .csv files? I want to
import them to the database.

split and ubound maybe

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)

Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know how to
select [what] from thisfile.csv so that I can get a string with commas:-(

Why do you need to have this? Once you have split a line of text into
an array, you will have the VALUES for an INSERT statement.

"INSERT INTO Tbl (cola, colb, colc...) VALUES (" & a(0) & "," & .....

The problem is how many cola, colb...., and how many a(0), a(1)? Actually
how can I get the value of a(0)?
Alternatively, if you are looking to open the CSV file with an ADO
type command, you will nee to find the appropriate connection string,
then issue a statement like...

"SELECT * FROM File.csv" (or something like that).

When I do this string, the 16 digit of barcode (9876543210123456) in the
fields all become (9.87654321012345E+15) in the database. Because when it is
inserted into the db, it may be recognized as a number. When I export a text
file, the conversion can't be reversed, and will be a text string
9.87654321012345E+15. How can I do to avoid from this conversion?
 
D

Dan Brussee

Dan Brussee said:
How can I know the number of columns of the .csv files? I want to
import them to the database.

split and ubound maybe

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)


Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know how to
select [what] from thisfile.csv so that I can get a string with commas:-(

Why do you need to have this? Once you have split a line of text into
an array, you will have the VALUES for an INSERT statement.

"INSERT INTO Tbl (cola, colb, colc...) VALUES (" & a(0) & "," & .....

The problem is how many cola, colb...., and how many a(0), a(1)? Actually
how can I get the value of a(0)?
Alternatively, if you are looking to open the CSV file with an ADO
type command, you will nee to find the appropriate connection string,
then issue a statement like...

"SELECT * FROM File.csv" (or something like that).

When I do this string, the 16 digit of barcode (9876543210123456) in the
fields all become (9.87654321012345E+15) in the database. Because when it is
inserted into the db, it may be recognized as a number. When I export a text
file, the conversion can't be reversed, and will be a text string
9.87654321012345E+15. How can I do to avoid from this conversion?

How about changing the field type to text?
 
A

atse

How can I know the number of columns of the .csv files? I want to
import them to the database.

split and ubound maybe

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)


Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know
how
to
select [what] from thisfile.csv so that I can get a string with commas:-(


Why do you need to have this? Once you have split a line of text into
an array, you will have the VALUES for an INSERT statement.

"INSERT INTO Tbl (cola, colb, colc...) VALUES (" & a(0) & "," & .....

The problem is how many cola, colb...., and how many a(0), a(1)? Actually
how can I get the value of a(0)?
Alternatively, if you are looking to open the CSV file with an ADO
type command, you will nee to find the appropriate connection string,
then issue a statement like...

"SELECT * FROM File.csv" (or something like that).

When I do this string, the 16 digit of barcode (9876543210123456) in the
fields all become (9.87654321012345E+15) in the database. Because when it is
inserted into the db, it may be recognized as a number. When I export a text
file, the conversion can't be reversed, and will be a text string
9.87654321012345E+15. How can I do to avoid from this conversion?

How about changing the field type to text?

I set the field type of the table in the db is "VARCHAR" (also try "TEXT").
But what about the other point on the previous question? Thanks
 
D

Dan Brussee

How can I know the number of columns of the .csv files? I want to
import them to the database.

split and ubound maybe

s = "a,b,c,d,e"
a = split(s, ",")
n = ubound(a)

At this point, n should equal 4 since a is a zero based array. Any
more than this, I will have to charge you a consulting fee :)


Here is a signed blank cheque ready for you :)

Yes, if I can't get the string of one of the rows. but I don't know how
to
select [what] from thisfile.csv so that I can get a string with commas:-(


Why do you need to have this? Once you have split a line of text into
an array, you will have the VALUES for an INSERT statement.

"INSERT INTO Tbl (cola, colb, colc...) VALUES (" & a(0) & "," & .....

The problem is how many cola, colb...., and how many a(0), a(1)? Actually
how can I get the value of a(0)?

Alternatively, if you are looking to open the CSV file with an ADO
type command, you will nee to find the appropriate connection string,
then issue a statement like...

"SELECT * FROM File.csv" (or something like that).


When I do this string, the 16 digit of barcode (9876543210123456) in the
fields all become (9.87654321012345E+15) in the database. Because when it is
inserted into the db, it may be recognized as a number. When I export a text
file, the conversion can't be reversed, and will be a text string
9.87654321012345E+15. How can I do to avoid from this conversion?

How about changing the field type to text?

I set the field type of the table in the db is "VARCHAR" (also try "TEXT").
But what about the other point on the previous question? Thanks

If you use the recordset access, check out the recordset's field
collection and it's count property...

NumCols = rs.Fields.Count

If you are using the array method, use ubound.

dim a() as string

a = split(txt, ",")

NumCols = ubound(a)

Getting the value of a(0) seems to be pretty obvious...

ValueOfAZero = a(0)
 
A

atse

If you use the recordset access, check out the recordset's field
collection and it's count property...

NumCols = rs.Fields.Count

This is what I want, thanks.
If you are using the array method, use ubound.

dim a() as string

Can't define like this in ASP, it complains with "error 800a0401 Expected
end of statement"
a = split(txt, ",")

What is txt?
NumCols = ubound(a)

Getting the value of a(0) seems to be pretty obvious...

ValueOfAZero = a(0)

Once I get the rs.Fields.Count value, I can get value of rs(0),
rs(1),...rs(rs.Fields.Count). Is it the same with a(0)...?

BTW, I still have the problem of the number with 16 digits in a text file.
In the 15th column there is a barcode in the csv file, like
9876543210123456. When I select it, the rs(14) = "9.87654321012345E+15" is
display. So, when I insert the records into the database, even I set that
field as VARCHAR or TEXT, the value is still 9.87654321012345E+15. Is there
any idea to void this conversion? Thanks a lot.

Atse
 
A

atse

William Tasso said:
I would guess the conversion is being made before it hits the database. the
spec for csv files allows for a string identifier - usually " (double
quote) - but can be anything.

Yes, before inserting into the database, I display them on the page, and it
looks converted. But how can I ADD anything to this number and force it to a
string instead of a number?
 
D

Dan Brussee

William Tasso said:
I would guess the conversion is being made before it hits the database. the
spec for csv files allows for a string identifier - usually " (double
quote) - but can be anything.

Yes, before inserting into the database, I display them on the page, and it
looks converted. But how can I ADD anything to this number and force it to a
string instead of a number?

As suggested, surround the item in the csv file with quotes.

......., "9876543210123456", .....
 
A

atse

As suggested, surround the item in the csv file with quotes.
......, "9876543210123456", .....

How can I add them to a thousand barcode in a csv file? Any idea?
Thanks,

Atse
 
D

Dan Brussee

How can I add them to a thousand barcode in a csv file? Any idea?
Thanks,
<sigh>
Well, if you are not creating the CSV file, then you would need to do
a transformation using some other method I guess. Maybe a VB app? Any
way of regenerating the CSV file, adding the quotes this time?
 
A

atse

Dan Brussee said:
<sigh>
Well, if you are not creating the CSV file, then you would need to do
a transformation using some other method I guess. Maybe a VB app? Any
way of regenerating the CSV file, adding the quotes this time?

OK, if no other choice, I think I have to do so. I will use Excel to edit
the field containing the long number by using CONCATENATE with some symbols
like ** and 123... Anyway, thanks you all!
Atse
 

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,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top