?
Solved

C# update

Posted on 2014-04-10
9
Medium Priority
?
127 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
[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
  • 7
  • 2
9 Comments
 
LVL 27

Assisted Solution

by:Shaun Kline
Shaun Kline earned 1500 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 27

Accepted Solution

by:
Shaun Kline earned 1500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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