-1

I currently have a SqlDataSource where I have used query builder to join 2 tables (product table and customer order table). The customer order table is composed of ProductID, Totalproduct and Updatedproduct while I joined the ProductQuantity from the Products table.

What I want to do is upon button click it will subtract the total product from the product quantity and update it in the updated product column. Any way or method in which I can have reference to on how to do it?

What i have in mind is something like Insert Into CustomerProducts VALUES(UpdatedProduct) = TotalProduct - ProductQuantity *** something like this. thank you sirs

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Reine Viray
  • 65
  • 2
  • 11

2 Answers2

0

Since you need to update a table on the basis of other table, you need to join the tables on some criteria. Just check the below link for more details.

How can I do update statement with join in SQL?

Hope it Helps.

Community
  • 1
  • 1
vivek
  • 1,595
  • 2
  • 18
  • 35
  • @Id is a sql variable that you need to pass. This is the primary key for the row that you need to update. If you need to update all the rows, remove the where clause from the query. – vivek Jun 25 '16 at 11:48
  • thank you sir. why is it giving me an error `Invalid column name 'ProductQuantity'.` i am using sql data source query builder sir – Reine Viray Jun 25 '16 at 11:50
  • You should ask question that is clear and provide almost all details related to the question. First, it seem to me that, there is only one table and now you said there are two tables. You also have mentioned that you have a `SqlDataSource`. This is totally confusing for solving the actual problem. First think it properly and then edit your question with all details. Then I wil help you. Thanks – vivek Jun 25 '16 at 11:59
  • Which database you are using 'Sql Server' or 'Mysql'? – vivek Jun 25 '16 at 12:24
  • sql server 2008 sir – Reine Viray Jun 25 '16 at 12:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115587/discussion-between-vivek-and-reine-viray). – vivek Jun 25 '16 at 12:26
  • sir thank you for helping me out. can you guide me w my other query? http://stackoverflow.com/questions/38028834/update-sql-column-using-a-button-field-asp-net – Reine Viray Jun 25 '16 at 13:09
0

To update your products use the query Update CustomerProducts set UpdateProduct = TotalProduct - ProductQuantity this will update all of your table rows.

  • can you help me out sir? http://stackoverflow.com/questions/38029650/ambiguous-column-name-productid-in-asp-net/38029658?noredirect=1#comment63502505_38029658 – Reine Viray Jun 25 '16 at 17:32