Solved

C# update

Posted on 2014-04-10
9
122 Views
Last Modified: 2014-04-14
Hi all, I'm trying to update my app with multiple table and column...actually I need to update just one column "serialnumber3" look at  my app in the screenshot attached

the reason I have added more than 2 table is because future update needs.

and here is my code that not working:

string Query = "update d.PONumber, b.ItemLookupCode, a.SerialNumber, a.SerialNumber2, a.SerialNumber3=@status from rmsmasterdbtest.dbo.Serial AS A"
            + " inner join dbo.item AS B on b.id = a.ItemID"
            + " inner join dbo.PurchaseOrderEntry AS C on C.ItemID = b.ID"
            + " inner join dbo.PurchaseOrder AS D on D.ID = c.PurchaseOrderID where ponumber";
            
           

            SqlConnection Myconn = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand(Query, Myconn);

            
            
            cmd.Parameters.AddWithValue("@status", this.txtstatus.Text);

Open in new window

Untitled.png
0
Comment
Question by:Moti Mashiah
  • 7
  • 2
9 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 500 total points
ID: 39992623
The syntax for an update is:
Update <single table name>
SET <column name> = <value>, ....
FROM <tables / views joined together>
WHERE <column name> = <value>

Open in new window

The FROM clause is optional and is only needed when your values come from a secondary table.

You cannot update multiple tables at once.
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39992640
You are saying that i can't update multiple columns from different tables?
0
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39992646
Yes. You would need to have separate update statements for each table that you wish to update.

Also, because you would need multiple update statements, you should wrap your update statements in a transaction, so that if one of the updates fails, all changes are rolled back.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39992682
K , Thanks ,

I would like to present it for you differently and explain my goal maybe it make more sense.

I have basically 2 tables and I'm going to work with two columns each one from other table.

1. table: purchaseorder - column: ponumber
2. table: serial - column: - serialnumber3

I have dropbox that show the ponumber column so all I need is to update column serialnumber against the ponumber these both table has private ID key that connect between them.

Please see screenshot
Capture.JPG
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39992805
K I simplify things all I need now is to do this update from single table see my code:

string Query = "update rmsmasterdbtest.dbo.serial set serialnumber=this.combosr.Text, serialnumber3='" + this.txtstatus.Text + "' where serialnumber=this.combosr.Text'" ;";

Open in new window

0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39992853
"update rmsmasterdbtest.dbo.serial set serialnumber=this.combosr.Text, serialnumber3='" + this.txtstatus.Text + "' where serialnumber=this.combosr.Text'" ;";

Open in new window


please can you help with this code it is not working for me.
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39992874
I uploaded screenshot I have one combo box and one text box both are in the same table and I would like to update the textbox depend on the dropobox item.

please do you have the code for this I can't make it work.


thanks
Capture.JPG
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39999824
I've requested that this question be closed as follows:

Accepted answer: 0 points for motimash's comment #a39992874
Assisted answer: 250 points for Shaun_Kline's comment #a39992623
Assisted answer: 250 points for Shaun_Kline's comment #a39992646

for the following reason:

doesn't really help
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39999825
Helped but didn't solve my issue
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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