C# 执行SQLServer数据库中的存储过程,新增数据
1 2 3 4 5 6 7 8 9
| 存储过程名:SP_Check_Equipotential 参数: @Part2GNDInfo varchar(3000), @Part2GND decimal(3,2), @Resultflag int output, @ResultMessage varchar(4000)output 返回值: @Resultflag int output, @ResultMessage varchar(4000)output
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| SqlConnection DbConnection = new SqlConnection(m_MESConnString); SqlCommand command = new SqlCommand("SP_Check_Equipotential", DbConnection); DbConnection.Open(); InitCommand(ref command); command.Parameters["@Part2GNDInfo"].Value = Part2GNDInfo; command.Parameters["@Part2GND"].Value = Convert.ToDecimal(mo2o(dr["步骤一最大值"],true)); command.ExecuteNonQuery(); int result = command.Parameters["@Resultflag"].Value.zInt32(); string ResultMessage = command.Parameters["@ResultMessage"].Value.ToString();
private static void InitCommand(ref SqlCommand command) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Part2GNDInfo", SqlDbType.VarChar, 3000); SqlParameter Part2GND = new SqlParameter("@Part2GND", SqlDbType.Decimal); Part2GND.Precision = 3; Part2GND.Scale = 2; command.Parameters.Add(Part2GND); command.Parameters.Add("@Resultflag", SqlDbType.Int, 1); command.Parameters["@Resultflag"].Direction = ParameterDirection.Output; command.Parameters.Add("@ResultMessage", SqlDbType.VarChar, 4000); command.Parameters["@ResultMessage"].Direction = ParameterDirection.Output; }
|