本文整理汇总了C#中IDataColumn类的典型用法代码示例。如果您正苦于以下问题:C# IDataColumn类的具体用法?C# IDataColumn怎么用?C# IDataColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDataColumn类属于命名空间,在下文中一共展示了IDataColumn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddRow
public void AddRow(string tableName, IDataColumn[] columns)
{
if (columns.Length > 0) {
bool localConnection = false;
if (ConnectionState == System.Data.ConnectionState.Closed) {
localConnection = true;
OpenConnection();
}
try {
string command = "INSERT INTO " + tableName;
string columnsToAdd = columns[0].Name;
string valuesToAdd = "\'" + VerifyValueString(columns[0].Value.ToString()) + "\'";
for (int i = 1; i < columns.Length; i++) {
columnsToAdd += ", " + columns[i].Name;
valuesToAdd += ", \'" + VerifyValueString(columns[i].Value.ToString()) + "\'";
}
command += " (" + columnsToAdd + ") VALUES (" + valuesToAdd + ")";
using (SQLiteCommand comm = new SQLiteCommand(command, connection)) {
comm.ExecuteScalar();
}
} finally {
if (localConnection) {
CloseConnection();
}
}
}
}
开发者ID:ChaotixBluix,项目名称:framework,代码行数:27,代码来源:SQLite.cs
示例2: BanPlayer
// Bans a player
public static void BanPlayer(DatabaseConnection dbConnection, string ip, string bannedID, string bannedAccount,
string bannedMac, string bannerID, string bannerIP, string unbanDate, Enums.BanType banType)
{
IDataColumn[] columns = new IDataColumn[] {
dbConnection.Database.CreateColumn(true, "BannedPlayerID", bannedID),
dbConnection.Database.CreateColumn(false, "BannedPlayerAccount", bannedAccount),
dbConnection.Database.CreateColumn(false, "BannedPlayerIP", ip),
dbConnection.Database.CreateColumn(false, "BannedPlayerMac", bannedMac),
dbConnection.Database.CreateColumn(false, "BannerPlayerID", bannerID),
dbConnection.Database.CreateColumn(false, "BannerPlayerIP",bannerIP),
dbConnection.Database.CreateColumn(false, "BannedDate", DateTime.Now.ToString()),
dbConnection.Database.CreateColumn(false, "UnbanDate", unbanDate),
dbConnection.Database.CreateColumn(false, "BanType", ((int)banType).ToString())
};
dbConnection.Database.AddRow("bans", columns);
}
开发者ID:ScruffyKnight,项目名称:PMU-Server,代码行数:17,代码来源:Bans.cs
示例3: GetPropertyName
/// <summary>
/// 修正字段名,在FixName的基础上,去掉表名前缀
/// </summary>
/// <param name="field"></param>
/// <returns></returns>
public virtual String GetPropertyName(IDataColumn field)
{
String name = field.Name;
if (Config.AutoCutPrefix)
{
String s = CutPrefix(name);
if (field.Table.Columns.Exists(item => item.Name == s)) name = s;
//if (!Array.Exists<IDataColumn>(field.Table.Columns, delegate(IDataColumn item) { return item.Name == s; })) name = s;
String str = ClassName;
if (!s.Equals(str, StringComparison.OrdinalIgnoreCase) &&
s.StartsWith(str, StringComparison.OrdinalIgnoreCase) &&
s.Length > str.Length && Char.IsLetter(s, str.Length))
s = s.Substring(str.Length);
//if (!Array.Exists<IDataColumn>(field.Table.Columns, delegate(IDataColumn item) { return item.Name == s; })) name = s;
if (field.Table.Columns.Exists(item => item.Name == s)) name = s;
}
if (Config.AutoFixWord)
{
name = FixWord(name);
}
return name;
}
开发者ID:windygu,项目名称:asxinyunet,代码行数:28,代码来源:XCoderBase.cs
示例4: GuessRelation
/// <summary>猜测表间关系</summary>
/// <param name="table"></param>
/// <param name="rtable"></param>
/// <param name="rname"></param>
/// <param name="column"></param>
/// <param name="name"></param>
/// <returns></returns>
public virtual Boolean GuessRelation(IDataTable table, IDataTable rtable, String rname, IDataColumn column, String name)
{
if (name.Length <= rtable.Name.Length || !name.StartsWith(rtable.Name, StringComparison.OrdinalIgnoreCase)) return false;
var key = name.Substring(rtable.Name.Length);
var dc = rtable.GetColumn(key);
// 猜测两表关联关系时,两个字段的类型也必须一致
if (dc == null || dc.DataType != column.DataType) return false;
// 建立关系
var dr = table.CreateRelation();
dr.Column = column.Name;
dr.RelationTable = rtable.Name;
dr.RelationColumn = dc.Name;
// 表关系这里一般是多对一,比如管理员的RoleID=>Role+Role.ID,对于索引来说,不是唯一的
dr.Unique = false;
// 当然,如果这个字段column有唯一索引,那么,这里也是唯一的。这就是典型的一对一
if (column.PrimaryKey || column.Identity)
dr.Unique = true;
else
{
var di = table.GetIndex(column.Name);
if (di != null && di.Unique) dr.Unique = true;
}
dr.Computed = true;
if (table.GetRelation(dr) == null) table.Relations.Add(dr);
// 给另一方建立关系
//foreach (IDataRelation item in rtable.Relations)
//{
// if (item.Column == dc.Name && item.RelationTable == table.Name && item.RelationColumn == column.Name) return dr;
//}
if (rtable.GetRelation(dc.Name, table.Name, column.Name) != null) return true;
dr = rtable.CreateRelation();
dr.Column = dc.Name;
dr.RelationTable = table.Name;
dr.RelationColumn = column.Name;
// 那么这里就是唯一的啦
dr.Unique = true;
// 当然,如果字段dc不是主键,也没有唯一索引,那么关系就不是唯一的。这就是典型的多对多
if (!dc.PrimaryKey && !dc.Identity)
{
var di = rtable.GetIndex(dc.Name);
// 没有索引,或者索引不是唯一的
if (di == null || !di.Unique) dr.Unique = false;
}
dr.Computed = true;
if (rtable.GetRelation(dr) == null) rtable.Relations.Add(dr);
return true;
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:61,代码来源:IModelResolver.cs
示例5: GetFormatParam
protected override string GetFormatParam(IDataColumn field, DataRow dr)
{
String str = base.GetFormatParam(field, dr);
if (String.IsNullOrEmpty(str)) return str;
if (str == "(-1)" && field.DataType == typeof(String)) return String.Format("({0})", Database.LongTextLength);
if (field.DataType == typeof(Guid)) return "(36)";
return str;
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:10,代码来源:MySql.cs
示例6: AlterColumnSQL
public override string AlterColumnSQL(IDataColumn field, IDataColumn oldfield)
{
return String.Format("Alter Table {0} Modify Column {1}", FormatName(field.Table.Name), FieldClause(field, false));
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:4,代码来源:MySql.cs
示例7: GetFieldConstraints
protected override string GetFieldConstraints(IDataColumn field, Boolean onlyDefine)
{
String str = null;
if (!field.Nullable) str = " NOT NULL";
if (field.Identity) str = " NOT NULL AUTO_INCREMENT";
return str;
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:9,代码来源:MySql.cs
示例8: GetFieldType
protected override string GetFieldType(IDataColumn field)
{
if (field.DataType == typeof(Boolean)) return "enum('N','Y')";
return base.GetFieldType(field);
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:6,代码来源:MySql.cs
示例9: DropColumnDescription
public Boolean DropColumnDescription(IDataColumn field)
{
return AddColumnDescription(field, null);
}
开发者ID:vebin,项目名称:soa,代码行数:4,代码来源:Access.cs
示例10: AddColumnDescription
public Boolean AddColumnDescription(IDataColumn field, String value)
{
try
{
using (ADOTabe table = GetTable(field.Table.Name))
{
if (table.Supported && table.Columns != null)
{
foreach (ADOColumn item in table.Columns)
{
if (item.Name == field.Name)
{
item.Description = value;
return true;
}
}
}
return false;
}
}
catch { return false; }
}
开发者ID:vebin,项目名称:soa,代码行数:22,代码来源:Access.cs
示例11: GetFieldDefault
/// <summary>取得字段默认值</summary>
/// <param name="field"></param>
/// <param name="onlyDefine">仅仅定义</param>
/// <returns></returns>
protected override string GetFieldDefault(IDataColumn field, bool onlyDefine)
{
// Access不能通过DDL来操作默认值
return null;
}
开发者ID:vebin,项目名称:soa,代码行数:9,代码来源:Access.cs
示例12: GetFieldConstraints
//protected override void FixIndex(IDataIndex index, DataRow dr)
//{
// base.FixIndex(index, dr);
// Boolean b = false;
// if (TryGetDataRowValue<Boolean>(dr, "PRIMARY_KEY", out b)) index.PrimaryKey = b;
// if (TryGetDataRowValue<Boolean>(dr, "UNIQUE", out b)) index.PrimaryKey = b;
//}
protected override string GetFieldConstraints(IDataColumn field, Boolean onlyDefine)
{
String str = base.GetFieldConstraints(field, onlyDefine);
if (field.Identity) str = " AUTOINCREMENT(1,1)" + str;
return str;
}
开发者ID:vebin,项目名称:soa,代码行数:17,代码来源:Access.cs
示例13: FixField
protected override void FixField(IDataColumn field, DataRow drColumn, DataRow drDataType)
{
base.FixField(field, drColumn, drDataType);
// 修正原始类型
String typeName = null;
if (TryGetDataRowValue<String>(drDataType, "TypeName", out typeName)) field.RawType = typeName;
}
开发者ID:vebin,项目名称:soa,代码行数:8,代码来源:Access.cs
示例14: FixField
protected override void FixField(IDataColumn field, DataRow dr)
{
// 修正原始类型
String rawType = null;
if (TryGetDataRowValue<String>(dr, "COLUMN_TYPE", out rawType)) field.RawType = rawType;
// 修正自增字段
String extra = null;
if (TryGetDataRowValue<String>(dr, "EXTRA", out extra) && extra == "auto_increment") field.Identity = true;
// 修正主键
String key = null;
if (TryGetDataRowValue<String>(dr, "COLUMN_KEY", out key)) field.PrimaryKey = key == "PRI";
// 注释
String comment = null;
if (TryGetDataRowValue<String>(dr, "COLUMN_COMMENT", out comment)) field.Description = comment;
// 布尔类型
if (field.RawType == "enum")
{
// MySql中没有布尔型,这里处理YN枚举作为布尔型
if (field.RawType == "enum('N','Y')" || field.RawType == "enum('Y','N')")
{
field.DataType = typeof(Boolean);
// 处理默认值
if (!String.IsNullOrEmpty(field.Default))
{
if (field.Default == "Y")
field.Default = "true";
else if (field.Default == "N")
field.Default = "false";
}
return;
}
}
base.FixField(field, dr);
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:39,代码来源:MySql.cs
示例15: FindDataType
protected override DataRow[] FindDataType(IDataColumn field, string typeName, bool? isLong)
{
// MySql没有ntext,映射到text
if (typeName.EqualIgnoreCase("ntext")) typeName = "text";
// MySql的默认值不能使用函数,所以无法设置当前时间作为默认值,但是第一个Timestamp类型字段会有当前时间作为默认值效果
if (typeName.EqualIgnoreCase("datetime"))
{
String d = field.Default; ;
if (CheckAndGetDefault(field, ref d) && String.IsNullOrEmpty(d)) typeName = "timestamp";
}
DataRow[] drs = base.FindDataType(field, typeName, isLong);
if (drs != null && drs.Length > 1)
{
// 无符号/有符号
if (!String.IsNullOrEmpty(field.RawType))
{
Boolean IsUnsigned = field.RawType.ToLower().Contains("unsigned");
foreach (DataRow dr in drs)
{
String format = GetDataRowValue<String>(dr, "CreateFormat");
if (IsUnsigned && format.ToLower().Contains("unsigned"))
return new DataRow[] { dr };
else if (!IsUnsigned && !format.ToLower().Contains("unsigned"))
return new DataRow[] { dr };
}
}
// 字符串
if (typeName == typeof(String).FullName || typeName.EqualIgnoreCase("varchar"))
{
foreach (DataRow dr in drs)
{
String name = GetDataRowValue<String>(dr, "TypeName");
if ((name == "NVARCHAR" && field.IsUnicode || name == "VARCHAR" && !field.IsUnicode) && field.Length <= Database.LongTextLength)
return new DataRow[] { dr };
else if (name == "LONGTEXT" && field.Length > Database.LongTextLength)
return new DataRow[] { dr };
}
}
// 时间日期
if (typeName == typeof(DateTime).FullName || typeName.EqualIgnoreCase("DateTime"))
{
// DateTime的范围是0001到9999
// Timestamp的范围是1970到2038
// MySql的默认值不能使用函数,所以无法设置当前时间作为默认值,但是第一个Timestamp类型字段会有当前时间作为默认值效果
String d = field.Default; ;
CheckAndGetDefault(field, ref d);
//String d = CheckAndGetDefault(field, field.Default);
foreach (DataRow dr in drs)
{
String name = GetDataRowValue<String>(dr, "TypeName");
if (name == "DATETIME" && String.IsNullOrEmpty(field.Default))
return new DataRow[] { dr };
else if (name == "TIMESTAMP" && String.IsNullOrEmpty(d))
return new DataRow[] { dr };
}
}
}
return drs;
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:64,代码来源:MySql.cs
示例16: AddDefault
public virtual Boolean AddDefault(IDataColumn field, String value)
{
//if (field.DataType == typeof(DateTime))
//{
CheckAndGetDefault(field, ref value);
//}
try
{
using (ADOTabe table = GetTable(field.Table.Name))
{
if (table.Supported && table.Columns != null)
{
foreach (ADOColumn item in table.Columns)
{
if (item.Name == field.Name)
{
item.Default = value;
return true;
}
}
}
return false;
}
}
catch { return false; }
}
开发者ID:vebin,项目名称:soa,代码行数:27,代码来源:Access.cs
示例17: FieldClause
public override string FieldClause(IDataColumn field, bool onlyDefine)
{
String sql = base.FieldClause(field, onlyDefine);
// 加上注释
if (!String.IsNullOrEmpty(field.Description)) sql = String.Format("{0} COMMENT '{1}'", sql, field.Description);
return sql;
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:7,代码来源:MySql.cs
示例18: DropDefault
public virtual Boolean DropDefault(IDataColumn field)
{
return AddDefault(field, null);
}
开发者ID:vebin,项目名称:soa,代码行数:4,代码来源:Access.cs
示例19: GetFieldDefault
protected override string GetFieldDefault(IDataColumn field, bool onlyDefine)
{
if (String.IsNullOrEmpty(field.Default)) return null;
if (field.DataType == typeof(Boolean))
{
if (field.Default == "true")
return " Default 'Y'";
else if (field.Default == "false")
return " Default 'N'";
}
else if (field.DataType == typeof(String))
{
// 大文本不能有默认值
if (field.Length <= 0 || field.Length >= Database.LongTextLength) return null;
}
//else if (field.DataType == typeof(DateTime))
//{
// String d = CheckAndGetDefaultDateTimeNow(field.Table.DbType, field.Default);
// if (d == "now()") d = "CURRENT_TIMESTAMP";
// return String.Format(" Default {0}", d);
//}
return base.GetFieldDefault(field, onlyDefine);
}
开发者ID:BiYiTuan,项目名称:soa,代码行数:25,代码来源:MySql.cs
示例20: FindDataType
protected override DataRow[] FindDataType(IDataColumn field, string typeName, bool? isLong)
{
DataRow[] drs = base.FindDataType(field, typeName, isLong);
if (drs != null && drs.Length > 0) return drs;
//// 处理SByte类型
//if (typeName == typeof(SByte).FullName)
//{
// typeName = typeof(Byte).FullName;
// drs = base.FindDataType(field, typeName, isLong);
// if (drs != null && drs.Length > 0) return drs;
//}
DataTable dt = DataTypes;
if (dt == null) return null;
// 转为整数
Int32 n = 0;
if (!Int32.TryParse(typeName, out n)) return null;
try
{
if (isLong == null)
{
drs = dt.Select(String.Format("NativeDataType={0}", n));
if (drs == null || drs.Length < 1) drs = dt.Select(String.Format("ProviderDbType={0}", n));
}
else
{
drs = dt.Select(String.Format("NativeDataType={0} And IsLong={1}", n, isLong.Value));
if (drs == null || drs.Length < 1) drs = dt.Select(String.Format("ProviderDbType={0} And IsLong={1}", n, isLong.Value));
}
}
catch { }
return drs;
}
开发者ID:vebin,项目名称:soa,代码行数:37,代码来源:Access.cs
注:本文中的IDataColumn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论