Solved

Update Database table with value selected from Dropdown !

Posted on 2007-11-21
9
859 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
9 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 125 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 125 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now