/// summary /// 运用实例 /// /summary public void getSqlPar() { SqlConnection scn = null; SqlCommand scm = null; DbParameter[] para ={ MakeParam("@job_desc", (DbType)SqlDbType.VarChar, 50, ParameterDirection.Input, "45"), }; using (scn = n
///
/// 运用实例
///
public void getSqlPar()
{
SqlConnection scn = null;
SqlCommand scm = null;
DbParameter[] para ={
MakeParam("@job_desc", (DbType)SqlDbType.VarChar, 50, ParameterDirection.Input, "45"),
};
using (scn = new SqlConnection())
{
scn.ConnectionString = "server=.;uid=sa;pwd=111111;database=pubs;";
scn.Open();
using (scm = new SqlCommand())
{
scm.Connection = scn;
scm.CommandType = CommandType.StoredProcedure;
scm.CommandText = "jobs_add_item";
foreach (DbParameter db in para)
{
scm.Parameters.Add(db);
}
scm.ExecuteNonQuery();
}
}
}
///
/// 生成参数
///
/// 存储过程名称
/// 参数类型
/// 参数大小
/// 参数方向
/// 参数所需要的值
///
public DbParameter MakeParam(string ParamName, DbType DbType, Int32 Size, ParameterDirection Direction, Object Value)
{
DbParameter param;
param = MakeParams(ParamName, DbType, Size);
param.Direction = Direction;
if (!(Direction == ParameterDirection.Output && Value == null))
param.Value = Value;
return param;
}
///
/// 生成一个不带值的参数
///
/// 参数名称
/// 参数类型
/// 参数大小
///
public DbParameter MakeParams(string ParamName, DbType DbType, Int32 Size)
{
SqlParameter param;
if (Size > 0)
param = new SqlParameter(ParamName, (SqlDbType)DbType, Size);
else
param = new SqlParameter(ParamName, (SqlDbType)DbType);
return param;
}