public void addparameter(String paramname, object paramtypenew, Int32 paramsize, object paramvalue, ParameterDirection paramdirection) { DbType paramtype = DbType.String; SqlDbType sqlparamtype = SqlDbType.VarChar; int i = 0; if (paramtypenew.GetType() == paramtype.GetType()) { paramtype = (DbType)paramtypenew; i = 1; } else { sqlparamtype = (SqlDbType)paramtypenew; i = 2; } SqlParameter param = new SqlParameter(); if (paramtype == DbType.String || sqlparamtype == SqlDbType.VarChar) { param.Size = paramsize; } param.ParameterName = paramname; if (i == 1) { param.DbType = paramtype; } if (i == 2) { param.SqlDbType = sqlparamtype; } param.Value = paramvalue; param.Direction = paramdirection; comobj.Parameters.Add(param); }
// <summary> // Aimed for NUnit testing. // </summary> public static string DBType2NUnitTestValue(DbType dbType_in) { switch (dbType_in) { case DbType.DateTime: case DbType.Date: case DbType.Time: // sql server friendly return("new DateTime(2341, 12, 12)"); case DbType.Int64: case DbType.UInt64: return("123L"); case DbType.Int16: case DbType.Int32: case DbType.UInt16: case DbType.UInt32: case DbType.Byte: case DbType.Single: case DbType.Double: case DbType.Decimal: return("123"); case DbType.Boolean: return("true"); case DbType.String: case DbType.StringFixedLength: case DbType.AnsiString: case DbType.AnsiStringFixedLength: return("\"123\""); case DbType.Guid: return("Guid.NewGuid()"); case DbType.Binary: return("new Byte[] { 1, 2, 3 }"); // ToDos: here! check if appropriate... //case DbType.Single: //return "0F"; // ToDos: here! } throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
public RemoteDataParameter(IDbDataParameter src, long objectId) { this.objectId = objectId; DbType = src.DbType; LogEnvironment.LogDebugEvent(null, DbType.GetType().FullName, (int)LogSeverity.Report, null); Direction = src.Direction; LogEnvironment.LogDebugEvent(null, direction.GetType().FullName, (int)LogSeverity.Report, null); isNullable = src.IsNullable; ParameterName = src.ParameterName; SourceColumn = src.SourceColumn; sourceVersion = src.SourceVersion; LogEnvironment.LogDebugEvent(null, sourceVersion.GetType().FullName, (int)LogSeverity.Report, null); value = src.Value; Precision = src.Precision; Scale = src.Scale; Size = src.Size; }
// <summary> // Aimed for NUnit testing. // </summary> public static string DBType2NUnitTestValue(DbType dbType_in) { switch (dbType_in) { case DbType.DateTime: case DbType.Date: case DbType.Time: { // sql server friendly return "new DateTime(2341, 12, 12)"; } case DbType.Int64: case DbType.UInt64: { return "123L"; } case DbType.Int16: case DbType.Int32: case DbType.UInt16: case DbType.UInt32: case DbType.Byte: case DbType.Single: case DbType.Double: case DbType.Decimal: { return "123"; } case DbType.Boolean: { return "true"; } case DbType.String: { return "\"123\""; } case DbType.Guid: { return "Guid.NewGuid()"; } case DbType.Binary: { return "new Byte[] { 1, 2, 3 }"; } // ToDos: here! check if appropriate... //case DbType.Single: //return "0F"; // ToDos: here! } throw new Exception(string.Format( "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
// ToDos: here! have a look at: sSqlDbType.cs #region public static string DbType2NSysType(...); // <summary> // Aimed for code generator, hence returning straight string. // NSysType - .Net System Type // </summary> public static string DbType2NSysType(DbType dbType_in) { switch (dbType_in) { case DbType.Boolean: { return "bool"; //typeof(bool).Name; } case DbType.Int16: { return typeof(Int16).Name; } case DbType.Int32: { return "int"; //typeof(int).Name; } case DbType.Int64: { return "long"; //typeof(long).Name; } case DbType.UInt16: { return typeof(UInt16).Name; } case DbType.UInt32: { return typeof(UInt32).Name; } case DbType.UInt64: { return typeof(UInt64).Name; } case DbType.String: { return "string"; //typeof(string).Name; } case DbType.DateTime: case DbType.Date: case DbType.Time: { return typeof(DateTime).Name; } case DbType.Guid: { return typeof(Guid).Name; } case DbType.Byte: { return typeof(Byte).Name; } case DbType.Object: { return typeof(Object).Name; } case DbType.Single: { // ToDos: here! check if appropriate... return typeof(Single).Name; } case DbType.Binary: { // ToDos: here! check if appropriate... return typeof(Byte[]).Name; } case DbType.Decimal: { // ToDos: here! check if appropriate... return typeof(Decimal).Name; } case DbType.Double: { // ToDos: here! check if appropriate... return typeof(Double).Name; } case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.Currency: case DbType.SByte: case DbType.StringFixedLength: case DbType.VarNumeric: { // ToDos: here! break; } default: { break; } } throw new Exception(string.Format( "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
// <summary> // Aimed for NUnit testing. // </summary> public static string DBType2NUnitTestValue(DbType dbType_in) { switch (dbType_in) { case DbType.DateTime: case DbType.Date: case DbType.Time: // sql server friendly return "new DateTime(2341, 12, 12)"; case DbType.Int64: case DbType.UInt64: return "123L"; case DbType.Int16: case DbType.Int32: case DbType.UInt16: case DbType.UInt32: case DbType.Byte: case DbType.Single: case DbType.Double: case DbType.Decimal: return "123"; case DbType.Boolean: return "true"; case DbType.String: case DbType.StringFixedLength: case DbType.AnsiString: case DbType.AnsiStringFixedLength: return "\"123\""; case DbType.Guid: return "Guid.NewGuid()"; case DbType.Binary: return "new Byte[] { 1, 2, 3 }"; // ToDos: here! check if appropriate... //case DbType.Single: //return "0F"; // ToDos: here! } throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
// ToDos: here! have a look at: sSqlDbType.cs #region public static string DbType2NSysType(...) { // <summary> // Aimed for code generator, hence returning straight string. // NSysType - .Net System Type // </summary> /// <param name="dbType_in"></param> /// <returns></returns> public static string DbType2NSysType(DbType dbType_in) { switch (dbType_in) { case DbType.Boolean: return "bool"; //typeof(bool).Name; case DbType.Int16: return typeof(short).Name; case DbType.Int32: return "int"; //typeof(int).Name; case DbType.Int64: return "long"; //typeof(long).Name; case DbType.UInt16: return typeof(ushort).Name; case DbType.UInt32: return typeof(uint).Name; case DbType.UInt64: return typeof(ulong).Name; case DbType.String: case DbType.StringFixedLength: case DbType.AnsiString: case DbType.AnsiStringFixedLength: return "string"; //typeof(string).Name; case DbType.DateTime: case DbType.Date: case DbType.Time: return typeof(DateTime).Name; case DbType.Guid: return typeof(Guid).Name; case DbType.Byte: return typeof(byte).Name; case DbType.Object: return typeof(object).Name; case DbType.Single: // ToDos: here! check if appropriate... return typeof(float).Name; case DbType.Binary: // ToDos: here! check if appropriate... return typeof(byte[]).Name; case DbType.Decimal: // ToDos: here! check if appropriate... return typeof(decimal).Name; case DbType.Double: // ToDos: here! check if appropriate... return typeof(double).Name; case DbType.Currency: case DbType.SByte: case DbType.VarNumeric: // ToDos: here! break; default: { break; } } throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
/// <summary> /// Gets the legal equivalent for the given <see cref="DbType"></see>. /// </summary> /// <param name="typeCode"></param> /// <returns></returns> public static object GetClrNullLegalEquivalent(DbType dbType) { switch (dbType) { case DbType.String: case DbType.StringFixedLength: case DbType.AnsiString: case DbType.AnsiStringFixedLength: return(null); case DbType.Int16: return(GetClrNullLegalEquivalent(TypeCode.Int16)); case DbType.Int32: return(GetClrNullLegalEquivalent(TypeCode.Int32)); case DbType.Int64: return(GetClrNullLegalEquivalent(TypeCode.Int64)); default: throw new NotSupportedException(string.Format("Cannot handle '{0}' ({1}).", dbType, dbType.GetType())); } }
// ToDos: here! have a look at: sSqlDbType.cs #region public static string DbType2NSysType(...) { // <summary> // Aimed for code generator, hence returning straight string. // NSysType - .Net System Type // </summary> /// <param name="dbType_in"></param> /// <returns></returns> public static string DbType2NSysType(DbType dbType_in) { switch (dbType_in) { case DbType.Boolean: return("bool"); //typeof(bool).Name; case DbType.Int16: return(typeof(short).Name); case DbType.Int32: return("int"); //typeof(int).Name; case DbType.Int64: return("long"); //typeof(long).Name; case DbType.UInt16: return(typeof(ushort).Name); case DbType.UInt32: return(typeof(uint).Name); case DbType.UInt64: return(typeof(ulong).Name); case DbType.String: case DbType.StringFixedLength: case DbType.AnsiString: case DbType.AnsiStringFixedLength: return("string"); //typeof(string).Name; case DbType.DateTime: case DbType.Date: case DbType.Time: return(typeof(DateTime).Name); case DbType.Guid: return(typeof(Guid).Name); case DbType.Byte: return(typeof(byte).Name); case DbType.Object: return(typeof(object).Name); case DbType.Single: // ToDos: here! check if appropriate... return(typeof(float).Name); case DbType.Binary: // ToDos: here! check if appropriate... return(typeof(byte[]).Name); case DbType.Decimal: // ToDos: here! check if appropriate... return(typeof(decimal).Name); case DbType.Double: // ToDos: here! check if appropriate... return(typeof(double).Name); case DbType.Currency: case DbType.SByte: case DbType.VarNumeric: // ToDos: here! break; default: { break; } } throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "undefined variable type: {0}", dbType_in.GetType().ToString() )); }
/// <summary> /// Determines the data type of a column in a statement /// </summary> /// <param name="stmt">The statement to retrieve information for</param> /// <param name="i">The column to retrieve type information on</param> /// <param name="typ">The CfType to receive the affinity for the given column</param> internal static void ColumnToType(DbType stmt, int i, CfType typ) { typ.Type = TypeNameToDbType(stmt.GetType().UnderlyingSystemType.Name); }