.net File Import

G

Guest

I am using visual studio with .Net and I am trying to import a text file into
a table

I have a date in this file ie
01012002
it is imported
1012002, stripping off the leading zero
I can't change the import file, that is the way is comes to me, but I need
to import the leading zero as well

how do I force it to give me exactly what is in the file, instead of making
the decision that it is a number and stripping the 0?

below is the code I am using

Dim objConnection As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPathName &
";Extended Properties=Text;HDR=Yes")
Dim objCommand As New OleDbCommand("SELECT * FROM " & sFileName,
objConnection)
Dim ExcelAdapter As New OleDbDataAdapter(objCommand)
objConnection.Open()

thanks
 
P

Paul Clement

¤ I am using visual studio with .Net and I am trying to import a text file into
¤ a table
¤
¤ I have a date in this file ie
¤ 01012002
¤ it is imported
¤ 1012002, stripping off the leading zero
¤ I can't change the import file, that is the way is comes to me, but I need
¤ to import the leading zero as well
¤
¤ how do I force it to give me exactly what is in the file, instead of making
¤ the decision that it is a number and stripping the 0?
¤
¤ below is the code I am using
¤
¤ Dim objConnection As New
¤ OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPathName &
¤ ";Extended Properties=Text;HDR=Yes")
¤ Dim objCommand As New OleDbCommand("SELECT * FROM " & sFileName,
¤ objConnection)
¤ Dim ExcelAdapter As New OleDbDataAdapter(objCommand)
¤ objConnection.Open()
¤
¤ thanks

You may need to use a schema.ini file and define your column as Text.

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


Paul
~~~~
Microsoft MVP (Visual Basic)
 
G

Guest

Thanks, your response was wonderful, but I am not quite done.
My file name is variable, the ini requires me to add the file name....

How do I pass the variable?

or I created a schema.xsd for the file, how do I cause this to be used when
bringing in the file?
 
P

Paul Clement

¤ Thanks, your response was wonderful, but I am not quite done.
¤ My file name is variable, the ini requires me to add the file name....
¤
¤ How do I pass the variable?
¤
¤ or I created a schema.xsd for the file, how do I cause this to be used when
¤ bringing in the file?

OK, maybe I misunderstood. Is this an XML file or a CSV file? Could you post a few sample lines from
the file?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
G

Guest

this is a csv, just trying to figure out a way to use schema
schema.ini requires a filename, and I won't know that, it will change with
each user. However I can put the file name in a variable. Can I use a
variable in schema.ini?

My other thought was is there a way to use schema.xsd to control the input
of a csv file? I apologize for the confusion.
 
P

Paul Clement

On Fri, 15 Apr 2005 13:50:01 -0700, "LadyRose"

¤ this is a csv, just trying to figure out a way to use schema
¤ schema.ini requires a filename, and I won't know that, it will change with
¤ each user. However I can put the file name in a variable. Can I use a
¤ variable in schema.ini?
¤
¤ My other thought was is there a way to use schema.xsd to control the input
¤ of a csv file? I apologize for the confusion.

Couple ways to handle this. One would be to simply rename the file (in code) to
that specified in your schema.ini file. The second would be to modify the
schema.ini file (using standard file i/o) to reflect the name of the csv file
you're going to process.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
I

Imran Arshad

Paul,
I have the same problem when reading the CSV file i created the schema.ini
file dynamically but i i want to import all field as text mean to say every
field data treated and loaded in data table as text.
Imran Arshad
 

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