Solved

Update Database table with value selected from Dropdown !

Posted on 2007-11-21
9
857 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

19 Experts available now in Live!

Get 1:1 Help Now