|
-
Sep 22nd, 2011, 07:34 AM
#1
Thread Starter
New Member
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
-
Sep 22nd, 2011, 11:16 AM
#2
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!
-
Sep 23rd, 2011, 02:49 PM
#3
Thread Starter
New Member
Re: update table
iNumeroColonne is the number of column of the table and it's always>12
-
Sep 23rd, 2011, 04:18 PM
#4
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?
-
Sep 25th, 2011, 05:02 AM
#5
Thread Starter
New Member
Re: update table
i have done but the table is not update and the option strict is on but no error was found
-
Sep 25th, 2011, 01:11 PM
#6
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.
-
Sep 26th, 2011, 02:23 AM
#7
Thread Starter
New Member
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
-
Sep 26th, 2011, 02:31 AM
#8
Re: update table
Check what value is returned by the call to Update on your DataAdapter. Is it zero or non-zero?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|