[c#]代码库
public static bool Insert_EvaluationInfo(int pvoteid, string pecontent, int plimited, out int id)
{
bool successful = false;
id = 0;
try
{
using (SqlConnection conn = new SqlConnection(strConn))
{
SqlCommand cmd = new SqlCommand("Insert_EvaluationInfo", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter spvoteid = new SqlParameter("@pVoteID", SqlDbType.Int);
spvoteid.Value = pvoteid;
SqlParameter spcontent = new SqlParameter("@pEContent", SqlDbType.NVarChar, 200);
spcontent.Value = pecontent.Trim();
SqlParameter splimited = new SqlParameter("@pLimitedNum", SqlDbType.Int);
splimited.Value = plimited;
SqlParameter resultid = new SqlParameter("@resultid", SqlDbType.Int);
resultid.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.AddRange(new SqlParameter[] { spvoteid, spcontent, splimited, resultid });
conn.Open();
if (cmd.ExecuteNonQuery().Equals(1))
{
int.TryParse(cmd.Parameters["@resultid"].Value.ToString(), out id);
successful = true;
}
conn.Close();
}
}
catch (Exception)
{
successful = false;
//throw;
}
return successful;
}
尽量不要使用out