本文整理匯總了C#中System.Data.DataTable.BeginLoadData方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.BeginLoadData方法的具體用法?C# DataTable.BeginLoadData怎麽用?C# DataTable.BeginLoadData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.BeginLoadData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DataReaderToDataSet
public static DataSet DataReaderToDataSet(IDataReader reader)
{
var ds = new DataSet();
DataTable table;
do
{
int fieldCount = reader.FieldCount;
table = new DataTable();
for (int i = 0; i < fieldCount; i++)
{
table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}
table.BeginLoadData();
var values = new Object[fieldCount];
while (reader.Read())
{
reader.GetValues(values);
table.LoadDataRow(values, true);
}
table.EndLoadData();
ds.Tables.Add(table);
} while (reader.NextResult());
reader.Close();
return ds;
}
示例2: ProcessResult
protected override DataTable ProcessResult(DataTable schema)
{
schema.BeginLoadData();
foreach (DataRow row in schema.Rows)
{
// ToBoolean
foreach (DataColumn col in schema.Columns)
if (col.Caption.StartsWith("IS_"))
row[col.Caption] =
row[col.Caption] != DBNull.Value &&
Convert.ToInt32(row[col.Caption], CultureInfo.InvariantCulture) != 0;
if (Convert.ToInt32(row["HELPER_CID"], CultureInfo.InvariantCulture) != 0)
row["SOURCE"] =
HelperGetObjectDefinition(Convert.ToInt32(row["HELPER_CID"], CultureInfo.InvariantCulture));
}
schema.EndLoadData();
schema.AcceptChanges();
schema.Columns.Remove("HELPER_CID");
return schema;
}
示例3: ProcessResult
protected override DataTable ProcessResult(DataTable schema)
{
schema.BeginLoadData();
foreach (DataRow row in schema.Rows)
{
// ToBoolean
foreach (DataColumn col in schema.Columns)
if (col.Caption.StartsWith("IS_"))
row[col.Caption] =
row[col.Caption] != DBNull.Value &&
Convert.ToInt32(row[col.Caption], CultureInfo.InvariantCulture) != 0;
row["MS_DBTOOLS_SUPPORT"] = (Convert.ToInt32(
HelperGetExtendedProperty(
"microsoft_database_tools_support", "schema", "dbo", "table",
row["TABLE_NAME"].ToString(), null, null),
CultureInfo.InvariantCulture) == 1);
}
schema.EndLoadData();
schema.AcceptChanges();
return schema;
}
示例4: ProcessResult
protected override DataTable ProcessResult(DataTable schema)
{
schema.BeginLoadData();
foreach (DataRow row in schema.Rows)
{
if (row["INPUTS"] == DBNull.Value)
{
row["INPUTS"] = 0;
}
if (row["OUTPUTS"] == DBNull.Value)
{
row["OUTPUTS"] = 0;
}
if (row["IS_SYSTEM_PROCEDURE"] == DBNull.Value ||
Convert.ToInt32(row["IS_SYSTEM_PROCEDURE"], CultureInfo.InvariantCulture) == 0)
{
row["IS_SYSTEM_PROCEDURE"] = false;
}
else
{
row["IS_SYSTEM_PROCEDURE"] = true;
}
}
schema.EndLoadData();
schema.AcceptChanges();
return schema;
}
示例5: ConvertDataReaderToDataTable
public static DataTable ConvertDataReaderToDataTable(DbDataReader reader)
{
try
{
DataTable table = new DataTable();
int fieldCount = reader.FieldCount;
for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex)
{
table.Columns.Add(reader.GetName(fieldIndex), reader.GetFieldType(fieldIndex));
}
table.BeginLoadData();
object[] rowValues = new object[fieldCount];
while (reader.Read())
{
reader.GetValues(rowValues);
table.LoadDataRow(rowValues, true);
}
reader.Close();
table.EndLoadData();
return table;
}
catch (Exception ex)
{
throw new Exception("DataReader轉換為DataTable時出錯!", ex);
}
}
示例6: GetDataSet
public static DataSet GetDataSet(String sqlString)
{
using (SqlCommand Cmd = new SqlCommand(sqlString))
try
{
Cmd.CommandText = sqlString;
Cmd.Connection = DbManager.Con;
SqlDataAdapter dbDataAdapter = new SqlDataAdapter(Cmd);
DataSet dataSet = new DataSet();
DataTable dataTable = new DataTable();
dataTable.BeginLoadData();
dbDataAdapter.Fill(dataTable);
dataTable.EndLoadData();
dataSet.EnforceConstraints = false;
dataSet.Tables.Add(dataTable);
return dataSet;
}
catch (Exception ex)
{
throw;
}
}
示例7: ConverDataReaderToDataTable
public static DataTable ConverDataReaderToDataTable(IDataReader reader)
{
if (reader == null)
{
return null;
}
DataTable table = new DataTable
{
Locale = CultureInfo.InvariantCulture
};
int fieldCount = reader.FieldCount;
for (int i = 0; i < fieldCount; i++)
{
table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}
table.BeginLoadData();
object[] values = new object[fieldCount];
while (reader.Read())
{
reader.GetValues(values);
table.LoadDataRow(values, true);
}
table.EndLoadData();
return table;
}
示例8: ToDataTable
public static DataTable ToDataTable(this TableData data, bool fillData = true, string tableNamePostfix = "")
{
var table = new DataTable(data.Name + tableNamePostfix);
var keys = new List<DataColumn>();
foreach (var field in data.Schema.Fields)
{
var type = field.ValueType;
var innerType = Nullable.GetUnderlyingType(type);
var col = table.Columns.Add(field.Name, innerType ?? type);
col.ExtendedProperties.Add("XFieldPosition", field);
if (field.FieldType == FieldType.Key)
{
keys.Add(col);
}
}
table.PrimaryKey = keys.ToArray();
if (fillData)
{
table.BeginLoadData();
foreach (var row in data.Rows)
{
var dataRow = table.NewRow();
for(var i = 0; i < data.Schema.Fields.Length; i++)
{
dataRow[i] = row[i];
}
table.Rows.Add(dataRow);
}
table.EndLoadData();
}
return table;
}
示例9: ReadCsvRawData
/// <summary>
/// Reads the CSV raw data.
/// </summary>
/// <returns>A temp DataTable object.</returns>
private DataTable ReadCsvRawData()
{
// Create a temp DataTable to hold data from CSV.
var tmpTable = new DataTable();
tmpTable.Columns.Add(LineNumberColumnName);
tmpTable.BeginLoadData();
CsvRow row;
bool firstRow = true;
while (this.reader.ReadRow(out row))
{
// Ignore empty lines
if (row.TotalColumns == 1 && row[0].IsNullOrWhitespace())
{
continue;
}
// In case the first line
if (firstRow)
{
foreach (string colName in row.Columns)
{
tmpTable.Columns.Add(colName);
}
firstRow = false;
}
else
{
int i = 1;
DataRow dr = tmpTable.NewRow();
dr[LineNumberColumnName] = row.LineNumber;
var columns = row.Columns;
foreach (string col in columns)
{
if (!col.IsNullOrWhitespace())
{
dr[i] = col;
}
i++;
}
tmpTable.Rows.Add(dr);
}
}
tmpTable.EndLoadData();
return tmpTable;
}
示例10: getDifferentRecords
public static DataTable getDifferentRecords(DataTable FirstDataTable, DataTable SecondDataTable)
{
FirstDataTable = FirstDataTable.Copy();
FirstDataTable.TableName += " First";
SecondDataTable = SecondDataTable.Copy();
SecondDataTable.TableName += " Second";
//Create Empty Table
DataTable ResultDataTable = new DataTable("ResultDataTable");
//use a Dataset to make use of a DataRelation object
using (DataSet ds = new DataSet())
{
//Add tables
ds.Tables.AddRange(new DataTable[] { FirstDataTable, SecondDataTable });
//Get Columns for DataRelation
DataColumn[] firstColumns = FirstDataTable.Columns.Cast<DataColumn>().ToArray();
DataColumn[] secondColumns = SecondDataTable.Columns.Cast<DataColumn>().ToArray();
//Create DataRelation
DataRelation r1 = new DataRelation(string.Empty, firstColumns, secondColumns, false);
ds.Relations.Add(r1);
//DataRelation r2 = new DataRelation(string.Empty, secondColumns, firstColumns, false);
//ds.Relations.Add(r2);
//Create columns for return table
List<DataColumn> PK = new List<DataColumn>();
for (int i = 0; i < FirstDataTable.Columns.Count; i++)
{
DataColumn newdc = ResultDataTable.Columns.Add(FirstDataTable.Columns[i].ColumnName, FirstDataTable.Columns[i].DataType);
if (FirstDataTable.PrimaryKey.Contains(FirstDataTable.Columns[i]))
PK.Add(newdc);
}
ResultDataTable.PrimaryKey = PK.ToArray();
//If FirstDataTable Row not in SecondDataTable, Add to ResultDataTable.
ResultDataTable.BeginLoadData();
foreach (DataRow parentrow in FirstDataTable.Rows)
{
DataRow[] childrows = parentrow.GetChildRows(r1);
if (childrows == null || childrows.Length == 0)
ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
}
////If SecondDataTable Row not in FirstDataTable, Add to ResultDataTable.
//foreach (DataRow parentrow in SecondDataTable.Rows)
//{
// DataRow[] childrows = parentrow.GetChildRows(r2);
// if (childrows == null || childrows.Length == 0)
// ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
//}
ResultDataTable.EndLoadData();
}
return ResultDataTable;
}
示例11: ExecuteReader
/// <summary>
/// Create a command and call ExecuteReader. Load the data into a DataTable
/// </summary>
/// <param name="commandText">The command text</param>
/// <param name="parameters">Parameters referring to @p1, @p2, ...</param>
/// <returns></returns>
public DataTable ExecuteReader(string commandText, params object[] parameters)
{
using (var command = this.CreateCommand(commandText, parameters))
using (var reader = command.ExecuteReader())
{
var result = new DataTable();
result.BeginLoadData();
result.Load(reader);
result.EndLoadData();
reader.Close();
return result;
}
}
示例12: ProcessResult
protected override DataTable ProcessResult(DataTable schema)
{
schema.BeginLoadData();
foreach (DataRow row in schema.Rows)
foreach (DataColumn col in schema.Columns)
if (col.Caption.StartsWith("IS_"))
row[col.Caption] =
row[col.Caption] != DBNull.Value &&
Convert.ToInt32(row[col.Caption], CultureInfo.InvariantCulture) != 0;
schema.EndLoadData();
schema.AcceptChanges();
return schema;
}
示例13: DataParser
public DataParser(string filename)
{
StreamReader reader = File.OpenText(filename);
string line;
string[] a;
while (null != (line = reader.ReadLine()))
{
a = line.Split(_Delimiter)
.Select<string, string>(s => s.Trim(_Quotes))
.ToArray();
// First line of text file contains
// schedule name
if (null == _Name)
{
_Name = a[0];
continue;
}
// Second line of text file contains
// schedule column names
if (null == _Table)
{
_Table = new DataTable();
foreach (string column_name in a)
{
DataColumn column = new DataColumn();
column.DataType = typeof(string);
column.ColumnName = column_name;
_Table.Columns.Add(column);
}
_Table.BeginLoadData();
continue;
}
// Remaining lines define schedula data
DataRow dr = _Table.LoadDataRow(a, true);
}
_Table.EndLoadData();
}
示例14: Distinct
public static DataTable Distinct(DataTable Table, DataColumn[] Columns)
{
//Empty table
DataTable table = new DataTable("Distinct");
//Sort variable
string sort = string.Empty;
//Add Columns & Build Sort expression
for(int i = 0; i < Columns.Length; i++)
{
table.Columns.Add(Columns[i].ColumnName,Columns[i].DataType);
sort += Columns[i].ColumnName + ",";
}
//Select all rows and sort
DataRow[] sortedrows = Table.Select(string.Empty,sort.Substring(0,sort.Length-1));
object[] currentrow = null;
object[] previousrow = null;
table.BeginLoadData();
foreach(DataRow row in sortedrows)
{
//Current row
currentrow = new object[Columns.Length];
for(int i = 0; i < Columns.Length; i++)
{
currentrow[i] = row[Columns[i].ColumnName];
}
//Match Current row to previous row
if(!RowEqual(previousrow, currentrow))
table.LoadDataRow(currentrow,true);
//Previous row
previousrow = new object[Columns.Length];
for(int i = 0; i < Columns.Length; i++)
{
previousrow[i] = row[Columns[i].ColumnName];
}
}
table.EndLoadData();
return table;
}
示例15: ListToDataTable
public static DataTable ListToDataTable(object list, Dictionary<string, string> titles, bool IsExportAllCol, string tableName)
{
if (string.IsNullOrEmpty(tableName))
{
var type = ZGeneric.GetGenericType(list);
tableName = ZGeneric.IsDynamicType(type) ? string.Empty : type.Name;
}
DataTable table = new DataTable(tableName);
table.BeginLoadData();
EachHelper.EachListHeader(list, (rowIndex, name, cellType) =>
{
if (IsExportAllCol || titles.ContainsKey(name))
{
string typeName = cellType.ToString();
if (cellType.IsGenericType)
typeName = cellType.GetGenericArguments()[0].ToString();
Type newType = Type.GetType(typeName, false);
if (newType != null)
{
//table.Columns.Add((titles[name] ?? name).ToString(), newType);
table.Columns.Add(name, newType);
}
}
});
EachHelper.EachListRow(list, (index, rowData) =>
{
DataRow row = table.NewRow();
EachHelper.EachObjectProperty(rowData, (cellIndex, name, value) =>
{
if (IsExportAllCol || titles.ContainsKey(name))
{
if (value != null && (Type.GetType(value.GetType().ToString(), false) != null))
//row[(titles[name] ?? name).ToString()] = value;
row[name] = value;
}
});
table.Rows.Add(row);
});
table.EndLoadData();
table.AcceptChanges();
return table;
}