Hello, I have database which that store the sold products in Orders Table and another table called Transaction to set the time and the total price for the individual order ,my question is: How to combined more than one order with only one Transaction number ,If there is any tables that I should to create or any thing to do to achieve the desired result.OrderedProducts|Price|Quantity|ProductName|OrderId| |10 | 2 | A | 1 | | 80 | 1 | C | 2 | | 30 | 5 | B | 3 | | 60 | 3 | B | 4 | ========================================Transaction | Date |TotalPrice| TrnNo |OrderId|| 12:10/05-11-14 | 10 | 1 | 1 || 12:11/05-11-14 | 180 | 1 | 2 || 12:16/05-11-14 | 30 | 2 | 3 || 12:17/05-11-14 | 90 | 2 | 4 |C# string conn = "server=.;uid=sa;pwd=123;database=PharmacyDB;"; SqlConnection con = new SqlConnection(); for (int i = 0; i < dgvSelectedItem.Rows.Count; i++) { SqlCommand cmd = new SqlCommand("storedP"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@prdctName", dgvSelectedItem.Rows[i].Cells[0].Value)); cmd.Parameters.Add(new SqlParameter("@ordrdQnty", dgvSelectedItem.Rows[i].Cells[2].Value)); cmd.Parameters.Add(new SqlParameter("@ordrPrice", dgvSelectedItem.Rows[i].Cells[3].Value)); con.ConnectionString = conn; cmd.Connection = con; con.Open(); cmd.Parameters.Add(cmd.ExecuteNonQuery()); cmd.ExecuteNonQuery(); con.Close(); }And this was my stored Procedure:CREATE proc [dbo].[store](@TrnId int,@prdctName nvarchar(50),@ordrdQnty int,@ordrPrice money,@OrdrId int,@TrnDate datetime,@TrnTotal money)asbegin transaction trsINSERT INTO [dbo].[OrderProduct](--[TrnId],[prdctName],[ordrdQnty],[ordrPrice])VALUES(--( SELECT @@IDENTITY from [Transaction] ),@prdctName,@ordrdQnty,@ordrPrice )if @@ERROR<>0 goto Err_INSERT INTO [dbo].[Transaction]([OrdrId],[TrnDate],[TrnTotal])VALUES( @OrdrId ,CURRENT_TIMESTAMP ,@TrnTotal)if @@ERROR<>0 goto Err_commit tranreturn 0Err_:rollbackreturn 1 Could you help me,please, thanks in advanced..
↧