Home All Groups Group Topic Archive Search About

Legacy Connection Object - I need a new one

Author
20 Apr 2006 10:54 AM
thejamie
My question: "What is the correct connection object to use in VS 2005 for a
text connection?" will need some background.  I am placing code at the end
showing how I am reading data from a text file (comma delimited) into a
dataset.  My problem is that the connection object I have used in the past
seems to be outdated:
[JET oledb 4.0 with the following modifications to the connection object:
Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Engine Type=96;Extended
Properties="Text;HDR=YES;Data Source=C:\vb6\myfile.txt;Jet OLEDB:Database
Locking Mode=0...]
I want to use the System.Data.SQLClient exclusively without any OLE objects
but cannot find the required connection object that will allow me to write
back to the text file.   Perhaps it isn't doable.   Code to create dataset=>
'=========================
    Public Function FlatFileDataSource(ByVal sFile As String) As DataTable
        'grabs flat file and places into dataset
        Dim SR As StreamReader
        Dim ReadBeginToEnd As String

        Dim dt As New DataTable
        Dim Rowz As Array
        Dim row As DataRow

        Dim bFirstlineHeader As Boolean
        Dim S As String
        Dim sTerminator As String = vbNullString
        Dim s As String

        SR = New StreamReader(sFile)
        ReadBeginToEnd = SR.ReadToEnd
        SR.Close()
        SR.Dispose()

        Rowz = Split(ReadBeginToEnd, vbNewLine)

        s = Rowz(0)
        Dim sArr As Array = Split(s, ",", -1)

        For Each s In sArr
            dt.Columns.Add(New DataColumn(s))
        Next

        For Each S In Rowz
            If Not bFirstlineHeader Then
                bFirstlineHeader = True
            Else
                row = dt.NewRow
                sTerminator = Replace(S, vbNewLine, "")
                row.ItemArray = Split(sTerminator, ",", -1)
                dt.Rows.Add(row)
            End If
        Next
        FlatFileDataSource = dt
    End Function
--
Regards,
Jamie
Incidentally - I accidently posted this in a VB forum.  I didn't realize
there was a difference between VB and VB.NET.  Apology here for any confusion
I have caused.

Author
20 Apr 2006 11:22 AM
Larry Lard
thejamie wrote:
> My question: "What is the correct connection object to use in VS 2005 for a
> text connection?" will need some background.  I am placing code at the end
> showing how I am reading data from a text file (comma delimited) into a
> dataset.  My problem is that the connection object I have used in the past
> seems to be outdated:
> [JET oledb 4.0 with the following modifications to the connection object:
> Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Engine Type=96;Extended
> Properties="Text;HDR=YES;Data Source=C:\vb6\myfile.txt;Jet OLEDB:Database
> Locking Mode=0...]
> I want to use the System.Data.SQLClient

That's (only) for talking to Microsoft SQL Server. OleDbClient is for
talking to everything else. <http://www.connectionstring.com> suggets
this for an OLE DB connection to a text file:

"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\txtFilesFolder\;Extended
Properties=""text;HDR=Yes;FMT=Delimited"""

    "HDR=Yes;" indicates that the first row contains columnnames, not
data

so I'd suggest that what you have at the moment is fine.

--
Larry Lard
Replies to group please
Author
20 Apr 2006 12:13 PM
thejamie
Larry,

Thanks.  I should have realized that.  My focus was on keeping code clean
and not whether it was practical.  Incidentally, the link you gave me for
connection strings is horribly commercial.   Carl Prothman's seems better to
me, at least.
http://www.carlprothman.net/Default.aspx?tabid=81

--
Regards,
Jamie


Show quoteHide quote
"Larry Lard" wrote:

>
> thejamie wrote:
> > My question: "What is the correct connection object to use in VS 2005 for a
> > text connection?" will need some background.  I am placing code at the end
> > showing how I am reading data from a text file (comma delimited) into a
> > dataset.  My problem is that the connection object I have used in the past
> > seems to be outdated:
> > [JET oledb 4.0 with the following modifications to the connection object:
> > Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Engine Type=96;Extended
> > Properties="Text;HDR=YES;Data Source=C:\vb6\myfile.txt;Jet OLEDB:Database
> > Locking Mode=0...]
> > I want to use the System.Data.SQLClient
>
> That's (only) for talking to Microsoft SQL Server. OleDbClient is for
> talking to everything else. <http://www.connectionstring.com> suggets
> this for an OLE DB connection to a text file:
>
>  "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\txtFilesFolder\;Extended
> Properties=""text;HDR=Yes;FMT=Delimited"""
>
>     "HDR=Yes;" indicates that the first row contains columnnames, not
> data
>
> so I'd suggest that what you have at the moment is fine.
>
> --
> Larry Lard
> Replies to group please
>
>
Author
20 Apr 2006 1:47 PM
Larry Lard
thejamie wrote:
> Larry,
>
> Thanks.  I should have realized that.  My focus was on keeping code clean
> and not whether it was practical.  Incidentally, the link you gave me for
> connection strings is horribly commercial.   Carl Prothman's seems better to
> me, at least.
> http://www.carlprothman.net/Default.aspx?tabid=81

Thanks, I must already owe Carl Prothman about ten drinks from back in
the ADO days, so another won't hurt :)

--
Larry Lard
Replies to group please