locked
Any easy Class method to update about 100 fields of a database using stored procedure? RRS feed

  • Question

  • User-100755152 posted

    Hi all,

     I am using  C# for ASP.NEt 2003.

    I would like to know if there is any easy method to update a database with about 100 fields in it.

    At present, I pass all the values of the controls on the web form to the stored procedure as parameters like :-

    myCommand.Parameters.Add("@CustomerID", SqlDbType.Int).Value = txtCustomerID.text

    Like this,  I add all 100 parameters.

    Is there any easy method to do it using a class or any other methods?

    Thanking you in advance,

    Tomy

     

    Wednesday, January 31, 2007 12:53 PM

Answers

  • User-1087479560 posted
    Hi,
    there is no easier way to do this with a build-in class.
    But you can make your own helper class.
    For instance, the 100 controls are in organized table, each one in one row. And the control's ID is the same as the column name.

    for(int i = 0; i < table.rows.count; i++)
    {
          control ctrl = table.rows[i].cells[0].controls[0];
            myCommand.Parameters.Add( "@" + ctrl.ID).value = ctrl.text;
    }

    Or you can maintain a column-control mapping table, and add the parameters according to this.
    Hope it helps.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 2, 2007 12:01 AM

All replies

  • User-1087479560 posted
    Hi,
    there is no easier way to do this with a build-in class.
    But you can make your own helper class.
    For instance, the 100 controls are in organized table, each one in one row. And the control's ID is the same as the column name.

    for(int i = 0; i < table.rows.count; i++)
    {
          control ctrl = table.rows[i].cells[0].controls[0];
            myCommand.Parameters.Add( "@" + ctrl.ID).value = ctrl.text;
    }

    Or you can maintain a column-control mapping table, and add the parameters according to this.
    Hope it helps.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 2, 2007 12:01 AM
  • User-100755152 posted

    Thank you very much.

    It was really a good logic.

    Tomy

     

    Tuesday, February 6, 2007 7:19 AM