Solved

Update Database table with value selected from Dropdown !

Posted on 2007-11-21
9
864 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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