none
Manually updating dataSet RRS feed

  • Question

  • Well, I need to create a manual code instead of sqlCommandBuilder , because comm.Builder only works if you work with one table. Well, I work with two tables. The point is that I need to create a code for updating values which are now already stored in the dataSet.
    This is my code so far:
    DataSet dataSet = new DataSet();
      SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT IDComponent, CurrentCycle FROM Components, Aircrafts WHERE Aircrafts.IDAircraft = '" + IDAvijona + "' " +
      "AND Aircrafts.IDAircraft = Components.IDAircraftFK", povezava);
      dataAdapter.Fill(dataSet);
      dataSet.Tables[0].TableName = "Cycles";
      foreach (DataRow dataRow in dataSet.Tables["Cycles"].Rows) 
      {
      if (dataRow["CurrentCycle"].Equals(DBNull.Value))
      {
      //If  cell in db has NULL value
      }
      else
      {
      dataRow["CurrentCycle"] = Convert.ToInt32(dataRow["CurrentCycle"]) + Convert.ToInt32(textBoxCycles.Text);
      }
      }
    As you can see in a database I have Table called "Components". In the table I have column IDComponent and CurrentCycle (I have more, but only these 2 are important for us now). Every one of them has a life time. Ones are limited on time, another on cycles. Now I am doing the code for cycles. 
    Important to know is , that the components are connected with the plane. 
    In the form I have a textBoxCycles in which user enters a number, which presents how many cycles plane did. And this number has to Add up to all the components for a particular plane - Specificlly has to add up to the CurrentCycle column. (And later on, when the currentCycle reaches LimitCycle, the component is  worn out - needs to be replaced, but this is not our problem now.)
    AS I said, the code above alredy reads the currentCycles for a plane the user chooses, and it add up the number from a listBox. So now I have numbers with the newest values, which are needed to be placed on the same spot where they were before. I was trying for 2 days to get into work, but no luck. I searched all the web, but didnt find notihng really useful.
    In my opinion, as far as I have learned, dataSet needs an IDComponent, not only CurrentCycle.If dataSet wants to put a number back from where it was taken, its needs to know the ID. (example: ID 3 has currentCycle 544, so after adding 3 cycles we got 547. ID of a component is needed to put the number 547 back on the same place where it was taken out before. 
    The problem maybe can occur when dataSet gets different IDs, for example IDs 3,4,5, 8,9, 15. (and so on). I mean, IDs not in a row. And to only these IDs has to re-ented currentCycles, for all the other number between has to leave empty, or enter null.
    And this is the hardest part. So I am asking you for a bit of a help, of course if you have any ideas or knowledge about it. I know its`s not so easy. I have a open thread in the msdn forum, but so far I havent got any really good answer. 
    Thx for you help. 

    I am a rookie at C#, so please don`t be mad if my questions goona sound stupid...
    • Moved by Figo Fei Wednesday, June 17, 2009 8:38 AM (From:Visual C# General)
    Tuesday, June 16, 2009 7:32 AM

Answers

  • Hey Mitja,

    From the picture that you displayed the code is incorrect when you use the Adapter and call Update. Instead of using CurrentCycle (your DataColumn name) use Cycles your table name.

    Thanks
    Chris Robinson
    Program Manager - DataSet


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, June 18, 2009 3:32 PM

All replies

  • The picture shows the error. Can someone please take a look what can be wrong?
    I am a rookie at C#, so please don`t be mad if my questions goona sound stupid...
    Tuesday, June 16, 2009 12:24 PM
  • Hey Mitja,

    From the picture that you displayed the code is incorrect when you use the Adapter and call Update. Instead of using CurrentCycle (your DataColumn name) use Cycles your table name.

    Thanks
    Chris Robinson
    Program Manager - DataSet


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, June 18, 2009 3:32 PM