Datagrid Update problem

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

    Datagrid Update problem

    Hello... Im having a problem getting a datagrid to update.
    Everything in my code looks ok so Im at a loss. I can
    click update and the grid will rebind... but not with my
    updated data. I am not posting back in pageload... And its
    not database permissions cause I can do inserts. Please
    Help! here is my code:

    Sub dgStaff_Update( ByVal sender As Object, ByVal e As
    DataGridCommand EventArgs)


    'Get values out of the datagrid to update
    Dim intID As Integer = e.Item.Cells(0) .Text
    Dim strGrp As String = e.Item.Cells(1) .Text
    Dim nameTextBox As TextBox = e.Item.Cells
    (2).FindControl ("txtDGName" )
    Dim posTextBox As TextBox = e.Item.Cells
    (3).FindControl ("txtDGPos")
    Dim numTextBox As TextBox = e.Item.Cells
    (4).FindControl ("txtDGNum")
    Dim strSql As String = "UPDATE tbl_parishstaff Set
    person=@person, pos=@pos, num=@num WHERE id=@id"

    'Create new update object and add parameters
    Dim updateClergySta ff As OleDb.OleDbComm and = New
    OleDb.OleDbComm and(strSql, Me.OleDbConnect ion1)

    updateClergySta ff.Parameters.A dd("@id", intID)
    updateClergySta ff.Parameters.A dd("@grp", strGrp)
    updateClergySta ff.Parameters.A dd("@person",
    nameTextBox.Tex t)
    updateClergySta ff.Parameters.A dd("@pos",
    posTextBox.Text )
    updateClergySta ff.Parameters.A dd("@num",
    numTextBox.Text )


    'Open the database, update the data, close
    database.
    updateClergySta ff.Connection.O pen()
    updateClergySta ff.ExecuteNonQu ery()
    Response.Write( updateClergySta ff.ExecuteNonQu ery.)
    updateClergySta ff.Connection.C lose()

    'After updating data fill grid with updated info
    and return to normal state
    dgStaff.EditIte mIndex = -1
    daStaff.Fill(Ds Staff1)
    dgStaff.DataBin d()
    End Sub
  • Cor Ligthert

    #2
    Re: Datagrid Update problem

    Brett,

    I see a lot, however what I don't see is where you set that new readed
    dataset to your datagrid as a datasource?

    Cor



    Comment

    • Brett

      #3
      Re: Datagrid Update problem

      Hi Cor... Thanks for the response....

      Doesnt the datasource get updated by the executenonquery ??
      If not, How would I go about setting it?

      Comment

      • Cor Ligthert

        #4
        Re: Datagrid Update problem

        Brett,

        I see that you do this.[color=blue]
        > dgStaff.EditIte mIndex = -1
        >daStaff.Fill(D sStaff1)
        >dgStaff.DataBi nd()[/color]

        I assume that that is your dataset so I would expect a
        dgStaff.Datasou rce = DsStaff

        Or something there

        Cor


        Comment

        • Guest's Avatar

          #5
          Re: Datagrid Update problem

          Hi Cor...

          dgStaff.Datasou rce = dsStaff1 is already being done in a
          prior statement. The datagrid does fill, just not with my
          updated data. Unless I need to refill it?? Do I need it in
          a different spot maybe? THis one is driving me nuts, as I
          dont really see anything wrong??

          Comment

          • Cor Ligthert

            #6
            Re: Datagrid Update problem

            Anonymous,

            Just try it, I assume that this can be (one) of the reasons you don't see
            the right information.

            Cor


            Comment

            • Brett

              #7
              Re: Datagrid Update problem

              Facetious,

              Tried it... same thing... :-(

              Whats strange is that if i response.write the parameters
              passed in they print out correctly (showing my changes).
              So its got to be somewhere in the update itself??? Or in
              the binding somewhere???

              -Frustrated (Brett)

              Comment

              • Cor Ligthert

                #8
                Re: Datagrid Update problem

                Brett,

                I don't understand your message. Is your actual database updated or is that
                not?

                What would than be strange that there is than not an error throwed when it
                is not.

                Cor


                Comment

                • Guest's Avatar

                  #9
                  Re: Datagrid Update problem

                  [color=blue]
                  >-----Original Message-----
                  >Brett,
                  >
                  >I don't understand your message. Is your actual database[/color]
                  updated or is that[color=blue]
                  >not?
                  >
                  >What would than be strange that there is than not an[/color]
                  error throwed when it[color=blue]
                  >is not.
                  >
                  >Cor[/color]
                  Cor,

                  Correct, The database is not getting updated. I would
                  think there should be an error too... but I hit update,
                  and the dataset rebinds to the grid without the updated
                  data... Strange :-( This is my first attempt at an update,
                  but from examples I have seen everthing looks to be in
                  place.

                  -Brett

                  Comment

                  • Cor Ligthert

                    #10
                    Re: Datagrid Update problem

                    Brett,
                    [color=blue]
                    > updateClergySta ff.ExecuteNonQu ery()
                    > Response.Write( updateClergySta ff.ExecuteNonQu ery.)
                    > updateClergySta ff.Connection.C lose()[/color]


                    What is that Response.Write a strange instruction espicaly that dot

                    I never did it this way, however can you change that for
                    \\\
                    try
                    updateClergySta ff.ExecuteNonQu ery
                    catch ex as exception
                    response.redire ct(ex.toString)
                    finally
                    updateClergySta ff.Connection.C lose()
                    end try

                    ///
                    Even when it was only to try now.

                    Cor


                    Comment

                    • Brett

                      #11
                      Re: Datagrid Update problem


                      lol... oopss... that shouldnt be in there... That was a
                      pasted in response.write that somehow has the
                      executenonquery in it. sorry bout that./

                      -Brett

                      Comment

                      Working...