Solved

C# update

Posted on 2014-04-10
9
120 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now