我正在使用带有数据库 SQL 的 Visual Studio 2010
我的 C# 代码是:
public void Gettotal(int matreqid)
{
int total = 0;
try
{
sqlconnstring = ConfigurationManager.ConnectionStrings["CONERP"].ConnectionString;
sqlcon = new SqlConnection(sqlconnstring);
sqlcon.Open();
sqlcmd = new SqlCommand("GettotalMaterialRequisition", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlda.SelectCommand.Parameters.Add("@matreqid", SqlDbType.BigInt).Value = matreqid;
sqlcmd.Parameters.Add("@mmtotal", SqlDbType.BigInt).Direction = ParameterDirection.ReturnValue;
sqlcmd.ExecuteNonQuery();
total = Convert.ToInt32(sqlcmd.Parameters["@mmtotal"].Value);
sqlcmd.Dispose();
sqlcon.Close();
}
catch (SqlException sqlerr)
{
}
}
和 SQL 存储过程是
ALTER procedure [dbo].[GettotalMaterialRequisition](@mmtotal bigint OUTPUT, @matreqid bigint)
as
begin
set @mmtotal = (select( sum (rate * qty * nooflab)) from MaterialRequisitionList where (matreqid = @matreqid and chkmr = 1))
RETURN @mmtotal;
end