Пример вызова хранимой процедуры и код хранимой процедуры.
Код
SqlCommand act = conn.CreateCommand();
conn.Open();
act.Transaction = conn.BeginTransaction(IsolationLevel.RepeatableRead);
try
{
act.CommandType = CommandType.StoredProcedure;
act.CommandText = "insert_act";
act.Parameters.AddWithValue("actnumber", SqlDbType.NVarChar).Value = actnumber.Text;
act.Parameters.AddWithValue("dateact", SqlDbType.DateTime).Value = DateTime.Parse(actdate.Value.Date.ToString());
act.Parameters.AddWithValue("company", SqlDbType.Int).Value = Int32.Parse(company.SelectedValue.ToString());
act.Parameters.AddWithValue("worker", SqlDbType.Int).Value = Int32.Parse(worcker.SelectedValue.ToString());
act.Parameters.AddWithValue("in_or_out", SqlDbType.Int).Value = 1;
act.Parameters.AddWithValue("document", SqlDbType.Image).Value = buf;
int idactnew = Int32.Parse(act.ExecuteScalar().ToString());
act.Transaction.Comit();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
подключение.close();
}
Код
USE [Sadko1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[insert_act]
@actnumber nvarchar(20),
@dateact datetime,
@company int,
@worker int,
@in_or_out bit,
@document image
AS
BEGIN
INSERT into [Акты] VALUES (@actnumber, @dateact, @company, @worker, @in_or_out, @document)
DECLARE @blank_now int
SELECT [ID Акта] From [Акты] Where ([Номер акта]= @actnumber AND [Дата]=@dateact AND [Страховая компания]=@company AND [Сотрудник]=@worker AND [Приход/Расход]=@in_or_out)
END