Dynamic update query in Tableadapter (strongly typed dataset)

Fullstop 21 Reputation points
2021-06-10T23:27:09.747+00:00

Hi
I have a strong typed dataset that has one table in it and is bound to a datagridview. I need to generate a dynamic update statement so I can update my datagridview on a cell change. So basically, when a cell is edited, I need to send the new value and the columname to the adapter an so it can update it respectively. I tried extending the adapter like this, but this seems to work only with select.. can someone help?

 public int UpdateNew(ScheduleTestDataSet.AppointmentsDataTable dataTable, string whereExpression)
        {
            string text1 = this.CommandCollection[2].CommandText;

            Debug.Print(text1);
            try
            {
                this.CommandCollection[2].CommandText =  whereExpression;
                Debug.Print(whereExpression);
                return this.Fill(dataTable);
            }
            finally { this.CommandCollection[2].CommandText = whereExpression; }
        }
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,276 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2021-06-10T23:45:13.043+00:00

    When using a TableAdapter one must understand these containers before venturing in and using them.

    The underlying code which most coders don't look at is under the covers and strongly typed, not very flexible and in your case not going to work.

    If you stick with a TableAdapter and need things to be dynamic, you need to write code to handle what a TableAdapter does not natively.

    0 comments No comments

  2. Fullstop 21 Reputation points
    2021-06-11T07:54:24.84+00:00

    this is a project that inherited, and it was so constructed back then, and it seems the only way around is to rewrite it :(

    0 comments No comments