How do i set DataRow class to last row of a Sql table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #16
    I am so turned around I don't even know where I am anymore.

    ArgumentExcepti on is usually thrown when you try to assign a value of one DataType to another DataType incorrectly (like if you Eixttime was a string and you tried to assign it to a DateTime object directly)

    As for the other error:
    Originally posted by msdn
    When created, the TargetInvocatio nException is passed a reference to the exception thrown by the method invoked through reflection. The InnerException property holds the underlying exception.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #17
      The problem you've described is very confusing.
      I think you might be trying to solve 2 things and have confused the actual problem.

      According to the specifications of the ArgumentExcepti on Class:

      "ArgumentExcept ion is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method"

      This means that you are passing a function a parameter that is not the right type.
      For example: you'll get this exception if you use a method that expects you to pass it a Date object but you pass it a String instead.

      According to the specifications of the TargetInvocatio nException Class:

      "The exception that is thrown by methods invoked through reflection."

      Double check any code that uses Reflection to make sure that it is properly used.

      Please re-describe your problem so that we can better understand it.
      Post any code snippets that may be the cause of the problem so that we can help you better.

      Thanks
      -Frinny

      Comment

      • pugalenthi
        New Member
        • Jan 2007
        • 44

        #18
        [CODE=CPP]
        int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
        DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
        thisRow["Exit_time"] = Exittime;
        thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
        thisAdapter.Upd ate(thisDataSet , "Table");
        [/code]
        I feel the problem is in the 4th line. Since im just updating one column data of an already exisiting row (last row), is there another way to do so.
        Last edited by Frinavale; Nov 6 '07, 02:06 PM. Reason: Added [code] tags to make more legible

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #19
          Originally posted by pugalenthi
          [code=cpp] int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
          DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
          thisRow["Exit_time"] = Exittime;
          thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
          thisAdapter.Upd ate(thisDataSet , "Table");[/code]

          I feel the problem is in the 4th line. Since im just updating one column data of an already exisiting row (last row), is there another way to do so.
          You should be able to just comment out that 4th line. The row is already in your table, why are you trying to add it again?

          Comment

          • pugalenthi
            New Member
            • Jan 2007
            • 44

            #20
            Originally posted by Plater
            You should be able to just comment out that 4th line. The row is already in your table, why are you trying to add it again?
            Ya i have tried that too, but the column named Exit_time in the last row is not getting modified when i run the code. In the table properties i have set the data type to Datetime and with null value allowed.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #21
              Well, I've never used this sort of stuff:
              thisAdapter.Upd ate(thisDataSet , "Table");

              I've always done it manually, so I don't know much about it.
              But I think that you have to like mark the row/colum as "edited" or "dirty" or something like that?

              Comment

              • pugalenthi
                New Member
                • Jan 2007
                • 44

                #22
                Originally posted by Plater
                But I think that you have to like mark the row/colum as "edited" or "dirty" or something like that?
                I dont understand what you mean.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #23
                  Try this?
                  [CODE=CPP]
                  int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
                  DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
                  thisRow["Exit_time"] = Exittime;
                  thisRow.SetModi fied();
                  thisAdapter.Upd ate(thisDataSet , "Table");
                  [/code]

                  Comment

                  • pugalenthi
                    New Member
                    • Jan 2007
                    • 44

                    #24
                    Originally posted by Plater
                    Try this?
                    [CODE=CPP]
                    int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
                    DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
                    thisRow["Exit_time"] = Exittime;
                    thisRow.SetModi fied();
                    thisAdapter.Upd ate(thisDataSet , "Table");
                    [/code]
                    I tried it, still im not able to modify the last row value.

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #25
                      Originally posted by pugalenthi
                      I tried it, still im not able to modify the last row value.
                      And that last row is the only thing not being saved? That's really strange.

                      Comment

                      • pugalenthi
                        New Member
                        • Jan 2007
                        • 44

                        #26
                        How about modifying the table using SQL UPDATE command. Please help me in running the SQL update command in c# to perform the modification.

                        Comment

                        • Plater
                          Recognized Expert Expert
                          • Apr 2007
                          • 7872

                          #27
                          From what I just read the Update() on a dataadapter only updates values in it's own "data" from the values you supply, it doesn't actually perform any writes back to the database?
                          Or at least is dependant on the .UpdateCommand like you said.

                          What does that .UpdateCommand look like?

                          Comment

                          • pugalenthi
                            New Member
                            • Jan 2007
                            • 44

                            #28
                            Originally posted by Plater
                            From what I just read the Update() on a dataadapter only updates values in it's own "data" from the values you supply, it doesn't actually perform any writes back to the database?
                            Or at least is dependant on the .UpdateCommand like you said.
                            But I was able to update the table when i used NewRow().

                            DataRow thisRow = thisDataSet.Tab les["Table"].NewRow();
                            thisRow["Exit_time"] = Exittime;
                            thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
                            thisAdapter.Upd ate(thisDataSet , "Table");

                            The only difference was i got the Exittime entered everytime in a new row.

                            Comment

                            Working...