I want to Update Column of a Table where ColumnName will be DropDown.SelectedValue.
Example: A set of RECORDS will be displayed from a Customer Table where CUstNo =’1234′ and City= ‘Chicago’ and Grade =’B’
Once displayed I want to Update the grade to ‘A’ of all those customers from the above criteria.
In My case I have like 100 Columns, so in where Clause Column Names will be selected from a DaropDown.
In My Query, Update Customer SET ColumnName= ‘some value’ where ColumnName =’ActualValue’
So how can I pass the ColumnName which is Dropdown Selected Value.
I believe I can’t give as
Update Customer SET DropDown.SelectedValue = ‘some value’ where DropDown.SelectedValue =’ActualValue’
How can I resolve this ?…
So it sounds like you want to build dynamic sql based on your grid? If that is the case you could always do something like
And then you could execute this statement. I don’t really know exactly what you are using but there are far better ways of making db updates. You could use an ORM like Linq to Sql or Entity Framework or you could even use something like a SqlCommandBuilder
EDIT: Here is an example in ASP.NET (although a winform app would be very similar)
Assume this dropdownlist is populated from some datasource
In the event handler build the updateStatement based on the selected column
The update statement string will look like this after the string is initialized(if Col1 is selected):
EDIT 2: Ok here is a sample in a winforms app
First i added a few values to the combobox. Next when my button on the form is clicked i take the selected value from the combo box and use it in the dynamic sql string. It will give you the same result as the asp.net solution above.