public static string GetDefaultValue(string s_type) { if (DBTypeConverter.IsSubstringOf("[]", s_type)) //数组为引用类型 { return("null"); } else if (DBTypeConverter.IsSubstringOf("string", s_type)) { return("\"\""); } else if (DBTypeConverter.IsSubstringOf("int", s_type) || DBTypeConverter.IsSubstringOf("int", s_type) || DBTypeConverter.IsSubstringOf("decimal", s_type) || DBTypeConverter.IsSubstringOf("float", s_type) || DBTypeConverter.IsSubstringOf("double", s_type) || DBTypeConverter.IsSubstringOf("short", s_type) || DBTypeConverter.IsSubstringOf("byte", s_type)) { return("0"); } else if (DBTypeConverter.IsSubstringOf("bool", s_type)) { return("false"); } else if (DBTypeConverter.IsSubstringOf("DateTime", s_type)) { return("DateTime.Now"); } else { return("null"); } }
public IDbDataParameter GetDbDataParameter(string paraName, string originDbType, int paraLen) { if (paraLen == 0) { return(new SqlParameter(paraName, DBTypeConverter.GetSqlDbTypeByOriginName(originDbType))); } return(new SqlParameter(paraName, DBTypeConverter.GetSqlDbTypeByOriginName(originDbType), paraLen)); }
//使用ADO.NET的GetSchemaTable方法 public DBTableDetail GetTableStruct2(string tableName) { DataSet ds = new DataSet(); IDbCommand cmd = this.dbEleFactory.GetCommand(); cmd.Connection = this.dbEleFactory.GetConnection(this.connectionStr); cmd.CommandText = string.Format("Select * from {0}", tableName); cmd.Connection.Open(); IDataReader read = cmd.ExecuteReader(); DataTable tb = read.GetSchemaTable(); //注意这句话,得到表的架构信息 read.Close(); cmd.Connection.Close(); DBTableDetail tableDetail = new DBTableDetail(); tableDetail.TableName = tableName; tableDetail.Columns = new DBColumnInfo[tb.Rows.Count]; for (int i = 0; i < tb.Rows.Count; i++) { tableDetail.Columns[i] = new DBColumnInfo(); tableDetail.Columns[i].ColumnName = tb.Rows[i]["ColumnName"].ToString(); tableDetail.Columns[i].ColumnType = DBTypeConverter.ConvertCsTypeToOriginDBType(tb.Rows[i]["DataType"].ToString()); if (tableDetail.Columns[i].ColumnType.ToString() == "image") { tableDetail.Columns[i].Length = 16; } else { tableDetail.Columns[i].Length = int.Parse(tb.Rows[i]["ColumnSize"].ToString()); } tableDetail.Columns[i].AllowNull = bool.Parse(tb.Rows[i]["AllowDBNull"].ToString()); tableDetail.Columns[i].IsAutoID = bool.Parse(tb.Rows[i]["IsAutoIncrement"].ToString()); tableDetail.Columns[i].Description = ""; tableDetail.Columns[i].DefaultValue = ""; } this.SetPKeys(tableDetail, tableName); return(tableDetail); }
public IDbDataParameter MakeOutParam(string ParamName, string originDbType, int Size) { return(MakeParam(ParamName, DBTypeConverter.GetOracleTypeByOriginName(originDbType), Size, ParameterDirection.Output, null)); }
public IDbDataParameter MakeInParam(string ParamName, string originDbType, object Value, int Size) { return(MakeParam(ParamName, DBTypeConverter.GetOracleTypeByOriginName(originDbType), Size, ParameterDirection.Input, Value)); }