/// <summary> /// 初始化 com.individual.helper.ComDbParameter 类的新实例 /// </summary> /// <param name="DataBaseType">数据库类型</param> /// <param name="ParameterName">参数名称</param> /// <param name="DbType">参数数据类型</param> /// <param name="Value">参数值</param> /// <param name="Direction">该值指示参数是只可输入、只可输出、双向还是存储过程返回值参数,System.Data.ParameterDirection 值之一</param> public static DbParameter CreateDbParameter(DataBaseType DataBaseType, string ParameterName, DbParameterType DbType, object Value, ParameterDirection Direction) { if (DataBaseType == helper.DataBaseType.Access) { System.Data.OleDb.OleDbParameter param = new System.Data.OleDb.OleDbParameter(ParameterName, GetOleDbType(DbType)); param.Direction = Direction; param.Value = Value; param.Size = 8000; return param; } else if (DataBaseType == helper.DataBaseType.MySql) { MySql.Data.MySqlClient.MySqlParameter param = new MySql.Data.MySqlClient.MySqlParameter(ParameterName, GetMySqlDbType(DbType)); param.Direction = Direction; param.Value = Value; param.Size = 8000; return param; } else if (DataBaseType == helper.DataBaseType.Oracle) { System.Data.OracleClient.OracleParameter param = new System.Data.OracleClient.OracleParameter(ParameterName, GetOracleType(DbType)); param.Direction = Direction; param.Value = Value; param.Size = 8000; return param; } else { System.Data.SqlClient.SqlParameter param = new System.Data.SqlClient.SqlParameter(ParameterName, GetSqlDbType(DbType)); param.Direction = Direction; param.Value = Value; param.Size = 8000; return param; } }
private static System.Data.SqlDbType GetSqlDbType(DbParameterType DbType) { if (DbType == DbParameterType.DateTime) { return System.Data.SqlDbType.DateTime; } else if (DbType == DbParameterType.Float) { return System.Data.SqlDbType.Float; } else if (DbType == DbParameterType.Int) { return System.Data.SqlDbType.Int; } else { return System.Data.SqlDbType.VarChar; } }
private static System.Data.OracleClient.OracleType GetOracleType(DbParameterType DbType) { if (DbType == DbParameterType.DateTime) { return System.Data.OracleClient.OracleType.DateTime; } else if (DbType == DbParameterType.Float) { return System.Data.OracleClient.OracleType.Float; } else if (DbType == DbParameterType.Int) { return System.Data.OracleClient.OracleType.Int32; } else { return System.Data.OracleClient.OracleType.VarChar; } }
private static System.Data.OleDb.OleDbType GetOleDbType(DbParameterType DbType) { if (DbType == DbParameterType.DateTime) { return System.Data.OleDb.OleDbType.DBTimeStamp; } else if (DbType == DbParameterType.Float) { return System.Data.OleDb.OleDbType.Double; } else if (DbType == DbParameterType.Int) { return System.Data.OleDb.OleDbType.Integer; } else { return System.Data.OleDb.OleDbType.VarChar; } }
private static MySql.Data.MySqlClient.MySqlDbType GetMySqlDbType(DbParameterType DbType) { if (DbType == DbParameterType.DateTime) { return MySql.Data.MySqlClient.MySqlDbType.DateTime; } else if (DbType == DbParameterType.Float) { return MySql.Data.MySqlClient.MySqlDbType.Float; } else if (DbType == DbParameterType.Int) { return MySql.Data.MySqlClient.MySqlDbType.Int32; } else { return MySql.Data.MySqlClient.MySqlDbType.String; } }