Link to home
Create AccountLog in
Avatar of jppinto
jppintoFlag for Portugal

asked on

Error message on update

I'm trying to read values from an text file and insert them to an Access database. I've the following code:

I'm getting an sintax error message (INSERT TO) on the" da.Update(ds, "TrunkLids")" line.

What is wrong with this?

Thanks,

JohnnyP
Private Sub btnCarregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCarregar.Click
        Dim ZSBTemp, InnerTemp, OuterTemp, HoraTemp, MesaTemp, DadosFile As String
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DbSource & ";"
        Try
            con.Open()
        Catch ex As Exception
            MsgBox("Erro ao abrir a Base de Dados. Mensagem original:" & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical)
        End Try
        sSQL = "SELECT * FROM [TrunkLids]"
        da = New OleDb.OleDbDataAdapter(sSQL, con)
        ds.Clear()
        da.Fill(ds, "TrunkLids")
 
        Dim dsNR As DataRow
        Dim cb = New OleDb.OleDbCommandBuilder(da)
        DadosFile = ""
        open.Filter = "Text Files (*.txt)|*.txt"
        open.Title = "Escolha um ficheiro de dados"
        If open.ShowDialog = DialogResult.OK Then
            Dim Linha As String
            Try 'abre o ficheiro e detecta possiveis erros
                FileOpen(1, open.FileName, OpenMode.Input)
                Linha = LineInput(1)
                Do Until EOF(1) 'Lê linhas do ficheiro
                    dsNR = ds.Tables("TrunkLids").NewRow
                    Linha = LineInput(1)
                    ZSBTemp = Mid(Linha, 5, 12)
                    InnerTemp = UCase(Mid(Linha, 18, 10))
                    OuterTemp = UCase(Mid(Linha, 29, 10))
                    HoraTemp = Mid(Linha, 40, 5)
                    MesaTemp = Mid(Linha, 48, 1)
                    DadosFile = DadosFile & ZSBTemp & "    " & InnerTemp & "    " & OuterTemp & "    " & HoraTemp & "    " & MesaTemp & "    " & vbCrLf
                    TextBox1.Text = DadosFile
                    dsNR.Item("ZSB") = ZSBTemp
                    dsNR.Item("Inner") = InnerTemp
                    dsNR.Item("Outer") = OuterTemp
                    dsNR.Item("Hora") = HoraTemp
                    dsNR.Item("Mesa") = MesaTemp
                    ds.Tables("TrunkLids").Rows.Add(dsNR)
                    da.Update(ds, "TrunkLids")
                Loop
                'TextBox1.Text = DadosFile
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                FileClose(1)
            End Try
            con.Close()
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account