Я сохранил процедуру следующим образом
ALTER PROCEDURE [dbo].[sp1]
@mat NVARCHAR(1000) = NULL,
@party NVARCHAR(1000) = NULL,
@place NVARCHAR(1000) = NULL,
@truk NVARCHAR(1000) = NULL,
@qty NUMERIC(10) = NULL,
@ptm NUMERIC(10) = NULL,
@mop NVARCHAR(100) = NULL,
@tos NVARCHAR(100) = NULL,
@driver NVARCHAR(100) = NULL,
@date1 DATE = NULL
AS
BEGIN
DECLARE @sql NVARCHAR(4000);
DECLARE @params NVARCHAR(4000);
DECLARE @rate NUMERIC(10);
SET @sql ='select @rate = ['+@mat+'] from tblcos'+ ' where [Name] = @party'
set @params = '@party nvarchar (1000), @rate NVARCHAR(10) OUTPUT'
exec sp_executesql @sql, @params,@party= @party,@rate = @rate OUTPUT
INSERT INTO tblsls([Party], [Place], [truk], [Material], [Qty], rate, [Amount], [Payment], [Balance], [MOP], [TOS], [driver], [Date])
SELECT
@party, @place, @truk, @mat, @rate, @qty, (@qty * @rate),
@ptm, (@qty * @rate - @ptm), @mop, @tos, @driver, @date1
END
Мой aspx.cs
файл
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection (@"
Data Source = ABC - PC; Initial Catalog = VRA; Integrated Security = True");
SqlCommand cmd = new SqlCommand("sp1", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Date", Calendar1.SelectedDate);
cmd.Parameters.AddWithValue("party", Ddprt.SelectedValue);
cmd.Parameters.AddWithValue("Place", tbpls.Text);
cmd.Parameters.AddWithValue("Truk", Tbtru.Text);
cmd.Parameters.AddWithValue("Material", Ddmat.SelectedValue);
cmd.Parameters.AddWithValue("Qty", Tbqty.Text);
**cmd.Parameters.AddWithValue("Rate", );**
**cmd.Parameters.AddWithValue("Amount", );**
cmd.Parameters.AddWithValue("Payment", Tbptm.Text);
**cmd.Parameters.AddWithValue("Balance", );**
cmd.Parameters.AddWithValue("MOP", Ddmop.SelectedValue);
cmd.Parameters.AddWithValue("TOS", Ddtos.SelectedValue);
cmd.Parameters.AddWithValue("driver", Tbdri.Text);
con.Open();
int k = cmd.ExecuteNonQuery();
if (k != 0)
{
Lbmsg.Text = "Record inserted successfully into the database";
Lbmsg.ForeColor = System.Drawing.Color.CornflowerBlue;
}
con.Close();
}
Как заставить Rate
, Amount
и Balance
принять значениеиз хранимой процедуры sp1
и обновить значение?