Results 1 to 8 of 8

Thread: update table

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    4

    update table

    hello i'm italian and i don't speack and write very well english
    i have one problem with a code can you help me

    form code
    Code:
    Private Sub cmdAggiornaEsci_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAggiornaEsci.Click
            Dim AggControl As UserModificaViaggio.UserModificaViaggio
            Dim ctrl As Control
            iViaggio = 0
            For Each ctrl In Me.Controls
    
                If TypeOf ctrl Is UserModificaViaggio.UserModificaViaggio Then
                    AggControl = ctrl
                    AggControl.AggiornaRecord(AggControl, AggControl.labelIDVIAGGIO0.Text, AggControl)
                End If
            Next
            iViaggio = 0
        End Sub
    usercontrol code

    Code:
    Public Sub AggiornaRecord(ByRef ctrlAdd As UserModificaViaggio, ByRef IDVIAGGIO As Integer, ByRef CheckDestinazione As Control)
            ConnParcoMacchine.ConnectionString = ParcoMacchineConnString
            sql = "SELECT * FROM VIAGGI;"
            Try
                ConnParcoMacchine.Open()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
            daParcoMacchine.SelectCommand = New OleDbCommand(sql, ConnParcoMacchine)
            daParcoMacchine.Fill(dsParcoMacchine, "VIAGGI")
            ConnParcoMacchine.Close()
    
            Dim cmdBuilderPosta As New OleDb.OleDbCommandBuilder(daParcoMacchine)
            cmdBuilderPosta.QuotePrefix = "["
            cmdBuilderPosta.QuoteSuffix = "]"
    
            daParcoMacchine.InsertCommand = cmdBuilderPosta.GetInsertCommand
            daParcoMacchine.UpdateCommand = cmdBuilderPosta.GetUpdateCommand
    
            Dim strFilter As String
            strFilter = "[IDVIAGGIO]=" & IDVIAGGIO
            Dim drPosta() As DataRow
            drPosta = dsParcoMacchine.Tables("VIAGGI").Select(strFilter)
            Dim myDr2 As DataRow
            Try
    
                For Each myDr2 In drPosta
                    myDr2.Item("TARGA") = ctrlAdd.ComboBoxTarga1.Text
                    myDr2.Item("KM ATTUALI") = ctrlAdd.TextBoxKMArrivo1.Text
                    myDr2.Item("ORA PARTENZA") = ctrlAdd.TextBoxOraPartenza1.Text
                    myDr2.Item("ORA ARRIVO") = ctrlAdd.TextBoxOraArrivo1.Text
                    myDr2.Item("DATA") = ctrlAdd.TextBoxData1.Text
                    myDr2.Item("DESTINAZIONE1") = ctrlAdd.ComboBoxDestinazione1.Text
                    'myDr2.Item("DESTINAZIONE2") = ctrlAdd.Controls("Destinazione1").Text
                    'myDr2.Item("DESTINAZIONE3") = ctrlAdd.Controls("Destinazione2").Text
                    'myDr2.Item("DESTINAZIONE4") = ctrlAdd.Controls("Destinazione3").Text
                    NumeroColonne()
                    Dim i As Integer
                    Dim sNomeCampo As String
                    Dim sNomeControllo As String
                    For i = 1 To iNumeroColonne - 12
                        sNomeCampo = "DESTINAZIONE" & (i + 1)
                        sNomeControllo = "Destinazione" & i
                        myDr2.Item(sNomeCampo) = ctrlAdd.Controls(sNomeControllo).Text
                    Next
                Next
                daParcoMacchine.Update(dsParcoMacchine, "VIAGGI")
            Catch ex As Exception
                MsgBox("errore", MsgBoxStyle.Critical, "errore")
            End Try
            
    
            dsParcoMacchine.Clear()
    the part of code with the f For i = 1 To iNumeroColonne - 12
    don't update the table could you help me thanks

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: update table

    Where is iNumeroColonne defined? If your iNumeroColonne is < 12 then your loop will never run, nothing will happen. Let me show you:

    Code:
    For i = 1 To iNumeroColonne - 12
    If iNumeroColonne = 5 ...

    Code:
    For i = 1 To 5 - 12
    For i = 1 To -7   'Bad!
    If iNumeroColonne = 15 ...

    Code:
    For i = 1 To 15 - 12
    For i = 1 To 3 'Good!

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    4

    Re: update table

    iNumeroColonne is the number of column of the table and it's always>12

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: update table

    sNomeControllo = "Destinazione" & i

    That line should be an error. i is a number, not a string.

    sNomeControllo = "Destinazione" & i.ToString

    Maybe you have not turned on OptionStrict/Explicit?

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    4

    Re: update table

    i have done but the table is not update and the option strict is on but no error was found

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: update table

    So you have this line above commented out:

    'myDr2.Item("DESTINAZIONE2") = ctrlAdd.Controls("Destinazione1").Text

    Did that line work? If so, are you reallllly sure that the iNumeroColonne > 12? Have you stepped through the code on each line to see what it is doing.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    4

    Re: update table

    i have checked all the line and all the line has done also the update of the table but after when i see the table it is not update

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: update table

    Check what value is returned by the call to Update on your DataAdapter. Is it zero or non-zero?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width