?
Solved

Update Database table with value selected from Dropdown !

Posted on 2007-11-21
9
Medium Priority
?
867 Views
Last Modified: 2013-12-16
Hi,
I am trying to update a database table field with the value selected from the deopdown list.
I want to save changes to the table with the new value.
How can I achieve this in C#.

Thank you.
0
Comment
Question by:srini4595
  • 3
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Yveau
ID: 20330811
... still doing homework ?
... update <table> set <column> = <value> ?!
0
 

Author Comment

by:srini4595
ID: 20330903
I don't understand what you say
0
 
LVL 18

Expert Comment

by:Yveau
ID: 20331005
The SQL needed for updating field <MyField> from table <MyTable> from value <OldValue> to value <NewValue> is:

update MyTable
set Myfield = NewValue
where Myfield = OldValue

The NewValue value should be passed from the dropdown listbox you are referring to.

Hope this helps ...
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:srini4595
ID: 20331047
I have a table as :
Name      ServerName      Active
ABC          server1            True
ABC          server2            False
ABC          server3            False
XYZ          server1            False
XYZ          server2            False
XYZ          server3            True
So in this table i have for one name only one server is active.
if i change the server name in the dropdown, then in  table the selected  server name should become active true and the rest should be false.      

Thank you.
0
 
LVL 18

Accepted Solution

by:
Yveau earned 500 total points
ID: 20331080
You need two updates for that !
And two parameters as well.

(no error handling, rollback or conditional commit in the example script !)

Hope this helps ...
begin tran
 
-- set all to false for @Name
update Table
set Active = false
where Name = @Name --> parameter for the name column needs to be passed.
 
-- set to true for @Name and @ServerName
update Table
set Active = true
where Name = @Name
and ServerName = @ServerName --> parameter for the ServerName needs to be passed
 
commit

Open in new window

0
 

Author Comment

by:srini4595
ID: 20331559
How do i get the value selected from dropdown into the Sql query.

cmd4 = new SqlCommand("Update sngConnectionTable set Active='True' where PipelineName='SNG' And ServerName=serverName",con);

where serverName is the one I want from the Dropdown.

Thank you.
0
 
LVL 1

Assisted Solution

by:arshadd
arshadd earned 500 total points
ID: 20333092
DropDownList1.SelectedValue this will give u the selected value of dropdownlist as a string. You need to hv to values i.e. currentValue and oldValue so that you can set active field accordingly
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question