本文整理汇总了C#中IDataColumn类的典型用法代码示例。如果您正苦于以下问题:C# IDataColumn类的具体用法?C# IDataColumn怎么用?C# IDataColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDataColumn类属于命名空间,在下文中一共展示了IDataColumn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例8: GetFieldType
protected override string GetFieldType(IDataColumn field)
{
if (field.DataType == typeof(Boolean)) return "enum('N','Y')";
return base.GetFieldType(field);
}
示例9: DropColumnDescription
public Boolean DropColumnDescription(IDataColumn field)
{
return AddColumnDescription(field, null);
}
示例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; }
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}