CSV..

  • Thread starter Thread starter Yogesh Shetty
  • Start date Start date
Y

Yogesh Shetty

Just curious to know is there any ole db provider for
reading csv/text files...

i know i can use Ole DB for ODBC ( Text Driver ) or also i
can use DTSFlatFile ( ships with sQL Server ) but i don't
want to install sql client on each of the client machine..

in addition is there any managed way of creating a DSN
rather than going trhu p/invoke...

thx in advance for your help...

regards
yogesh s
 
¤ Just curious to know is there any ole db provider for
¤ reading csv/text files...
¤
¤ i know i can use Ole DB for ODBC ( Text Driver ) or also i
¤ can use DTSFlatFile ( ships with sQL Server ) but i don't
¤ want to install sql client on each of the client machine..
¤
¤ in addition is there any managed way of creating a DSN
¤ rather than going trhu p/invoke...
¤

Use the Jet OLEDB driver, not the ODBC driver:

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "D:\My Documents\TextFiles" & ";" & _
"Extended Properties=""Text;HDR=NO;FMT=Delimited"""

Dim TextConn As New System.Data.OleDb.OleDbConnection(ConnectionString)
TextConn .Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM
Test#csv", TextConn)

If your text files use a field delimiter other than a comma you will need a
schema.ini file:

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

A DSN can be created via code. What kind of DSN do you want to create?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Thx for the reply.. now since Ole db supports full path so
there is no need for me to create a dsn...

but just fo rknowledge sake.. if i want to create a dsn
for Microsoft text driver.. how do i go using managed
code...
 
¤ Thx for the reply.. now since Ole db supports full path so
¤ there is no need for me to create a dsn...
¤
¤ but just fo rknowledge sake.. if i want to create a dsn
¤ for Microsoft text driver.. how do i go using managed
¤ code...
¤

The most common method is to use API function calls. The following creates a user DSN with a path to
the location of your text files:

Private Const ODBC_ADD_DSN As Short = 1 ' Add data source

Private Const vbAPINull As Integer = 0 ' NULL Pointer

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As
Integer, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As
Integer

Dim intRet As Integer
Dim strDriver As String
Dim strAttributes As String

'Set the attributes delimited by null.
strDriver = "Microsoft Text Driver (*.txt; *.csv)"
strAttributes = "DESCRIPTION=Text Files" & Chr(0)
strAttributes = strAttributes & "DSN=TextFilesDSN" & Chr(0)
strAttributes = strAttributes & "DBQ=e:\My Documents\TextFiles" & Chr(0)

intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet <> 0 Then
MsgBox("DSN Created")
Else
MsgBox("Create Failed")
End If


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top