Solved

Update Database table with value selected from Dropdown !

Posted on 2007-11-21
9
863 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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