update not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qatarya3sal
    New Member
    • Oct 2007
    • 11

    update not working

    [code=vbnet]Imports System.XML

    Public Class Form1
    Inherits System.Windows. Forms.Form

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    transactions = New Transaction() {}
    GCC.Open()
    End Sub

    Private Sub btnLoad_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnLoad.Click
    Dim action As String
    Dim country As String
    Dim month As Integer
    Dim year As Integer
    Dim amount As Double

    Dim document As XmlDocument
    Dim reader As XmlNodeReader

    Dim ofd As OpenFileDialog = New OpenFileDialog
    Dim result As DialogResult = ofd.ShowDialog
    If (result = DialogResult.Ca ncel) Then
    Return
    End If

    document = New XmlDocument
    document.Load(o fd.FileName)

    reader = New XmlNodeReader(d ocument)

    reader.Read() 'skip root node
    While reader.Read()
    If (reader.Name = "transactio n") Then
    reader.Read()
    action = reader.ReadElem entString
    country = reader.ReadElem entString
    month = reader.ReadElem entString
    year = reader.ReadElem entString
    amount = reader.ReadElem entString
    ReDim Preserve transactions(tr ansactions.Leng th)
    transactions(tr ansactions.Leng th - 1) = New Transaction(act ion, country, month, year, amount)
    End If
    End While

    Try

    Dim t As Transaction
    For Each t In Me.transactions

    If t.getAction = "insert" Then
    LNGAdapter.Inse rtCommand.Comma ndText = _
    "INSERT INTO LNGproduction (fldCountry, fldMonth, fldYear, fldAmount ) VALUES('" & _
    t.getCountry & "', " & t.getMonth & ", " & t.getYear & ", " & t.getAmount & ")"
    LNGAdapter.Inse rtCommand.Execu teNonQuery()

    ElseIf (t.getAction = "update") Then
    LNGAdapter.Upda teCommand.Comma ndText = _
    "UPDATE LNGproduction SET fldAmount=" & t.getAmount & "WHERE fldCountry=" & " AND" & t.getCountry & "' AND fldMonth=" & t.getMonth & _
    "AND fldYear=" & t.getYear
    LNGAdapter.Upda teCommand.Execu teNonQuery()


    ElseIf (t.getAction = "delete") Then
    LNGAdapter.Dele teCommand.Comma ndText = _
    "DELETE FROM LNGproduction WHERE fldCountry=" & " '" & t.getCountry & "' AND fldMonth=" & t.getMonth & _
    " AND fldYear=" & t.getYear
    LNGAdapter.Dele teCommand.Execu teNonQuery()

    End If
    Next

    Catch oleDbExceptionP arameter As System.Data.Ole Db.OleDbExcepti on
    Console.WriteLi ne(oleDbExcepti onParameter)

    End Try

    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

    LNGAdapter.Sele ctCommand.Comma ndText = TextBox1.Text
    LngDataSet.Clea r()
    LNGAdapter.Fill (LngDataSet, "LNGproduction" )
    DataGrid1.SetDa taBinding(LngDa taSet, "LNGproduction" )

    End Sub

    End Class[/code]


    The update not working with me i don't know why
    Last edited by debasisdas; Nov 12 '07, 08:58 PM. Reason: Formatted using code=vbnet tag.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    can you explain please what does this line of code means
    [code=vbnet]
    "UPDATE LNGproduction SET fldAmount=" & t.getAmount & "WHERE fldCountry=" & " AND" & t.getCountry & "' AND fldMonth=" & t.getMonth & _
    "AND fldYear=" & t.getYear
    [/code]

    What is the value for fldCountry ?

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by debasisdas
      can you explain please what does this line of code means
      [code=vbnet]
      "UPDATE LNGproduction SET fldAmount=" & t.getAmount & "WHERE fldCountry=" & " AND" & t.getCountry & "' AND fldMonth=" & t.getMonth & _
      "AND fldYear=" & t.getYear
      [/code]

      What is the value for fldCountry ?
      That looks like a pretty good candidate for why the update fails.

      Comment

      • qatarya3sal
        New Member
        • Oct 2007
        • 11

        #4
        Originally posted by debasisdas
        can you explain please what does this line of code means
        [code=vbnet]
        "UPDATE LNGproduction SET fldAmount=" & t.getAmount & "WHERE fldCountry=" & " AND" & t.getCountry & "' AND fldMonth=" & t.getMonth & _
        "AND fldYear=" & t.getYear
        [/code]

        What is the value for fldCountry ?

        Is string ... i don't know where the mistake

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Originally posted by qatarya3sal
          Is string ... i don't know where the mistake
          What my compatriots are alluding to is that you are attempting to perform an UPDATE which has a malformed WHERE clause. Your WHERE clause is malformed because you never specify a value for fldCountry.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            I'm gonna try and bold the problem areas:

            "UPDATE LNGproduction " _
            "SET "_
            "fldAmount= " & t.getAmount & _
            "WHERE " _
            "fldCountry =" & _
            " AND " & t.getCountry & _

            "' AND fldMonth=" & t.getMonth & _
            "AND fldYear=" & t.getYear

            As you notice there appears to be an extra "AND" in there, assuming that fldCountry should be tested with t.getCountry

            Comment

            Working...