DataGrid / DataView Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NetRacer

    #1

    DataGrid / DataView Problems

    hi,

    i have a DataGrid with a DataView as source. the data is read correctly from
    the db and shown on screen.
    the problem appears, when i want to add some rows to the grid.

    first it adds them and the ListChangedEven t from the DataView raises and the
    new values are shown correctly.
    but if i then click on the save button (which calls the EndCurrentEdit and
    Update methods), the DataView suddenly only has the original rows and the
    new ones are lost.

    then if i try again to add some values, they are lost imediately when i
    leave the current row in the DataGrid.

    there are no constraints, keys or other restrictions in the underlaying
    DataTable.

    a suggestion:
    at first addition of the row there raises a strange second ListChangedEven t
    after the ItemAdded. the ListChangedType is ItemMoved, then OldIndex equals
    the current row and the NewIndex something like -23423435. is my problem
    there?

    thx for any help
    netracer


  • Cor Ligthert

    #2
    Re: DataGrid / DataView Problems

    NetRacer,

    This is in my opinion impossible to answer without code.
    Can you show the code from this event.
    [color=blue]
    > but if i then click on the save button (which calls the EndCurrentEdit and
    > Update methods), the DataView suddenly only has the original rows and the
    > new ones are lost.[/color]

    Cor


    Comment

    • NetRacer

      #3
      Re: DataGrid / DataView Problems

      Private Function SaveDataGrids(B yVal grid As DataGrid, Optional ByVal
      ShowErrors As Boolean = True) As Boolean

      Dim cnt As Integer = 0
      Dim dvGrid As DataView

      dvGrid = CType(grid.Data Source, DataView)

      Dim daGrid As New MySqlDataAdapte r(String.Format ("SELECT * FROM {0}
      ", dvGrid.Table.Ta bleName), conn)
      Dim cbGrid As MySqlCommandBui lder

      Try
      cbGrid = New MySqlCommandBui lder(daGrid)

      '-----
      'if i set a breakpoint here, the record is already lost
      '-----
      Me.BindingConte xt(grid.DataSou rce).EndCurrent Edit()

      cnt = daGrid.Update(d vGrid.Table)

      'MessageBox.Sho w(cnt.ToString & " lines from " &
      dv.Table.TableN ame & " updated.", _
      '"Datenbankinfo ", MessageBoxButto ns.OK,
      MessageBoxIcon. Information)
      Catch ex As MySqlException
      If cnt <= 1 And ShowErrors Then
      MessageBox.Show (ex.Message, "Datenbankfehle r",
      MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
      End If
      Catch ex As Exception
      Debug.WriteLine (ex.ToString)
      End Try

      Return (cnt > 0)
      End Function




      "Cor Ligthert" <notmyfirstname @planet.nl> schrieb im Newsbeitrag
      news:Od2b9O0eFH A.1448@TK2MSFTN GP09.phx.gbl...[color=blue]
      > NetRacer,
      >
      > This is in my opinion impossible to answer without code.
      > Can you show the code from this event.
      >[color=green]
      >> but if i then click on the save button (which calls the EndCurrentEdit
      >> and Update methods), the DataView suddenly only has the original rows and
      >> the new ones are lost.[/color]
      >
      > Cor
      >[/color]


      Comment

      • NetRacer

        #4
        Re: DataGrid / DataView Problems

        ahhh... stop, i found the error. a property set of a form property reloaded
        the table from database. *grml*... stupid error


        Comment

        • Cor Ligthert

          #5
          Re: DataGrid / DataView Problems

          NetRacer,
          [color=blue]
          >
          > Dim daGrid As New MySqlDataAdapte r(String.Format ("SELECT * FROM {0}
          > ", dvGrid.Table.Ta bleName), conn)
          > Dim cbGrid As MySqlCommandBui lder
          >
          > Try
          > cbGrid = New MySqlCommandBui lder(daGrid)
          >[/color]
          You dataadapter has not any schemainformati on, how would it create the
          commands.

          I never did it this way, however you can try the Dataadapter.fil lschema in
          advance, I assume that it will solve your problem.

          http://msdn.microsoft.com/library/de...chematopic.asp

          There is written that it adds a datatable. Therefore I assume it is not
          going 1:1

          The datatable that uses your dvGrid is just dvGrid.DataTabl e

          I hope this helps,

          Cor



          Comment

          • NetRacer

            #6
            Re: DataGrid / DataView Problems

            the schema is/was not the problem. the command is created correctly.
            look the log of MySQL:

            "UPDATE `tbl_ersatz_abs ` SET `Rekl_ID`=1, `Pos`=4, `ErsatzAB`=1644 437,
            `ErsatzABText`= '@Y', `ZNA_ID`=4 WHERE `E_AB_ID` <=> 5 AND `Rekl_ID` <=> 1
            AND `Pos` <=> 4 AND `ErsatzAB` <=> 1644437 AND `ErsatzABText` <=> '@Z' AND
            `ZNA_ID` <=> 4; SELECT `E_AB_ID`, `Rekl_ID`, `Pos`, `ErsatzAB`,
            `ErsatzABText`, `ZNA_ID` FROM `tbl_ersatz_abs ` WHERE (`E_AB_ID`=5)"


            if you're not familiar with MySQL: the operator <=> does a 'NULL-safe equal'
            comparison.

            if i use FillSchema or the AddWithSchema option, the grid annoys me with
            popup boxes that i should set an ID. i don't want to set an ID in my
            program, i want the server to do this.

            by the way the Fill is done much earlier at loading the form.



            the problem was a few lines before the posted sub. another datasource was
            saved there and at the EndCurrentEdit of this saving a property set was
            called which did a new select on the database and so overwrote my changes.

            however, thanx for trying to help
            netracer



            "Cor Ligthert" <notmyfirstname @planet.nl> schrieb im Newsbeitrag
            news:OL4FpS7eFH A.2700@tk2msftn gp13.phx.gbl...[color=blue]
            > NetRacer,
            >[color=green]
            >>
            >> Dim daGrid As New MySqlDataAdapte r(String.Format ("SELECT * FROM
            >> {0} ", dvGrid.Table.Ta bleName), conn)
            >> Dim cbGrid As MySqlCommandBui lder
            >>
            >> Try
            >> cbGrid = New MySqlCommandBui lder(daGrid)
            >>[/color]
            > You dataadapter has not any schemainformati on, how would it create the
            > commands.
            >
            > I never did it this way, however you can try the Dataadapter.fil lschema in
            > advance, I assume that it will solve your problem.
            >
            > http://msdn.microsoft.com/library/de...chematopic.asp
            >
            > There is written that it adds a datatable. Therefore I assume it is not
            > going 1:1
            >
            > The datatable that uses your dvGrid is just dvGrid.DataTabl e
            >
            > I hope this helps,
            >
            > Cor
            >
            >
            >[/color]


            Comment

            • Cor Ligthert

              #7
              Re: DataGrid / DataView Problems

              NetRacer,

              I was misinterprettin g your code of MySQL. I thought: "is it MySQL or
              YourSQL?
              However just a kind of blindness it very clear.

              :-))

              Sorry

              Cor


              Comment

              • NetRacer

                #8
                Re: DataGrid / DataView Problems

                Ähhhm... sorry, but i could not really understand your joke (it was one,
                wasn't it?). i'm not a naturally english speaker (as you can see in my bad
                english, i think)...

                by the way: YourSQL really exists. it's a frontend tool for MySQL ;)

                however, thanx again for your try to help
                netracer



                "Cor Ligthert" <notmyfirstname @planet.nl> schrieb im Newsbeitrag
                news:OURjtt8eFH A.892@tk2msftng p13.phx.gbl...[color=blue]
                > NetRacer,
                >
                > I was misinterprettin g your code of MySQL. I thought: "is it MySQL or
                > YourSQL?
                > However just a kind of blindness it very clear.
                >
                > :-))
                >
                > Sorry
                >
                > Cor
                >[/color]


                Comment

                • Cor Ligthert

                  #9
                  Re: DataGrid / DataView Problems

                  Netracer

                  You can interpret it as a joke, it was just a stupid mistake from me reading
                  your code.

                  :-)

                  Cor


                  Comment

                  Working...