- using System;
- using System.Data;
- using System.Data.SqlClient;
- public sealed class DataHelper
- {
- // Constructor made private to prevent instantiation because this class
- // only contains static members
- private DataHelper() {}
- public static SqlParameter MakeInputParam(string name, SqlDbType type, int size, object val)
- {
- SqlParameter prm = new SqlParameter();
- prm.ParameterName = name;
- prm.SqlDbType = type;
- prm.Size = size;
- prm.Direction = ParameterDirection.Input;
- prm.Value = val;
- return prm;
- }
- public static SqlParameter MakeOutputParam(string name, SqlDbType type, int size)
- {
- SqlParameter prm = new SqlParameter();
- prm.ParameterName = name;
- prm.SqlDbType = type;
- prm.Size = size;
- prm.Direction = ParameterDirection.Output;
- return prm;
- }
- public static SqlParameter MakeInputOutputParam(string name, SqlDbType type, int size)
- {
- SqlParameter prm = new SqlParameter();
- prm.ParameterName = name;
- prm.SqlDbType = type;
- prm.Size = size;
- prm.Direction = ParameterDirection.InputOutput;
- return prm;
- }
- public static SqlParameter MakeReturnParam(string name)
- {
- SqlParameter prm = new SqlParameter();
- prm.ParameterName = name;
- prm.SqlDbType = SqlDbType.Int;
- prm.Direction = ParameterDirection.ReturnValue;
- return prm;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/12112012282.html
来源: http://www.codesnippet.cn/detail/12112012282.html