Question : Processing multiple textr files usiing dataadapter


Hi,

I have a program that performs the following loop

Select semi-colon separated text files

For each text file
     create connection string (using jet text reader)
     create dataadapter (da)
     create dataset        (ds)
     create select statement (Select * from FileName where Transdate >='20051001')
     Fill dataadapter  da.fill(ds)
     Load DataGridView (DGV) with ds.tables(0)
     Add columns + load new columns
     Load rows to database table
     dispose ds
     dispose da
     reset DGV
     close connection
Loop

Unfortunately I keep getting errors when refilling the dataadapter (generally Value of one or more parameters not set)

Any ideas?  Can I use a streamreader to load the DataGridView?

Regards,


Alan
     


Answer : Processing multiple textr files usiing dataadapter

I've isolated the problem to the SetupSemiColonSchemaIni sub.  I assume it would apply equally to the SetupCommaSchemaIni sub, although I haven't tested with that.

For some reason - which I can't at the moment fathom - the method by which that currently writes the file results in the LoadSource sub not recognising (or not completely recognising) the file even though (e.g.) the debug code within the LoadSource sub did so.  I am not sure whether the fault (and it looks to me like a bug) is specific to the .WriteLine method or more generally to the TextFileWriter version of the StreamWriter.  But a solution which has worked for me is to recode the SetupSemiColonSchemaIni sub to avoid both.

Here's my revision

    Sub SetupSemiColonSchemaIni2(ByVal fname As String)
        Me.Cursor = Cursors.WaitCursor
        AddTextToRTB("Start schema process")
        If My.Computer.FileSystem.FileExists(fname) Then
            Dim fiMyFile As IO.FileInfo = New IO.FileInfo(fname)

            'Ensure existing schema ini file is deleted
            AddTextToRTB("deleting existing schema")
            Try
                My.Computer.FileSystem.DeleteFile(fiMyFile.DirectoryName & "\schema.ini")
            Catch ex As Exception
                'catch the file missing error and ignore it
            End Try
            Dim f As New System.IO.StreamWriter(fiMyFile.DirectoryName & "\schema.ini")
            AddTextToRTB("Creating new schema for " & fiMyFile.Name)
            Dim t As String = "[" & fiMyFile.Name & "]" & vbCrLf
            t &= "Format=Delimited(;)" & vbCrLf
            t &= "ColNameHeader = " & chkHeaderRow.Checked & vbCrLf
            t &= "CharacterSet=ANSI" & vbCrLf
            t &= "col1=Source char width 255" & vbCrLf
            t &= "col2=Sub_System char width 255" & vbCrLf
            t &= "col3=ClientCode char width 255" & vbCrLf
            t &= "col4=Sap_Co char width 255" & vbCrLf
            t &= "col5=LSKU_Code char width 255" & vbCrLf
            t &= "col6=TransDate char width 255" & vbCrLf
            t &= "col7=Volume double" & vbCrLf
            t &= "col8=UoM char width 255" & vbCrLf
            t &= "col9=TradingPartner char width 255" & vbCrLf
            t &= "col10=SalesOrg char width 255" & vbCrLf
            t &= "col11=Distribution char width 255" & vbCrLf
            t &= "col12=SalesTerritory char width 255" & vbCrLf
            t &= "col13=APO_Mkt char width 255" & vbCrLf
            t &= "col14=Plant char width 255" & vbCrLf
            AddTextToRTB("Closing schema for " & fiMyFile.Name)
            f.Write(t)
            f.Close()
            f.Dispose()
            AddTextToRTB("Schema created for " & fiMyFile.Name)

        End If

        Me.Cursor = Cursors.Default

    End Sub

It is not as tidy as it might be in a number of respects but, for me, it works.  What I suggest you do is add this to your form, change all references to SetupSemiColonSchemaIni to SetupSemiColonSchemaIni2 and check that it works for you, too.  Although I've given it a reasonable amount of testing, that has been on a somewhat crippled version of your full program, as I didn't want - unless it was absolutely necessary - to have to do all that would be needed to make the database side of things work.  So there may be influences that my tests have not recognised.

If it does work for you then the basic problem is solved.  Tidying up would be the icing on the cake.

Roger  
Random Solutions  
 
programming4us programming4us