این تابع درجه:
public void InsCompany(string CompanyName,string SherkatType,string Address,string Tel1,string Tel2,string Fax,string Mobile,DateTime Ttasis)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "InsCompany";
cmd.Parameters.AddWithValue("@CompanyName", CompanyName);
cmd.Parameters.AddWithValue("@SherkatType", SherkatType);
cmd.Parameters.AddWithValue("@Address", Address);
cmd.Parameters.AddWithValue("@Tel1", Tel1);
cmd.Parameters.AddWithValue("@Tel2", Tel2);
cmd.Parameters.AddWithValue("@Fax", Fax);
cmd.Parameters.AddWithValue("@Mobile", Mobile);
cmd.Parameters.AddWithValue("@Ttasis", Ttasis);
mycmd.Connection = myCn;
if (myCn.State == ConnectionState.Closed)
{
myCn.Open();
}
mycmd.ExecuteNonQuery();
myCn.Close();
myCn.Dispose();
}
اینطوری پارامتر ها رو ارسال میکنم:
InsCompany(txtName.Text.Trim(), txtType.Text.Trim(), txtAddress.Text.Trim(), txtTel1.Text.Trim(), txtTel2.Text.Trim(), txtFax.Text.Trim(), txtMob.Text.Trim(), mydatetime);
پروسیجرم اینه:
CREATE PROC [dbo].[InsCompany]
@CompanyName nvarchar(50),
@SherkatType nvarchar(50),
@Address nvarchar(120),
@Tel1 nvarchar(13),
@Tel2 nvarchar(13),
@Fax nvarchar(13),
@Mobile nvarchar(13),
@Ttasis smalldatetime
as
INSERT INTO [MMdb].[dbo].[TCompany]
([CompanyName]
,[SherkatType]
,[Address]
,[Tel1]
,[Tel2]
,[Fax]
,[Mobile]
,[Ttasis])
VALUES
(@CompanyName,
@SherkatType,
@Address,
@Tel1,
@Tel2,
@Fax,
@Mobile,
@Ttasis)
SELECT @@IDENTITY 'IDENTITY'
چجوری این مقدار @@IDENTITY رو بدست بیارم؟
ممنون