Solved

C# update

Posted on 2014-04-10
9
121 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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