Solved

C# update

Posted on 2014-04-10
9
119 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

9 Experts available now in Live!

Get 1:1 Help Now