本文整理匯總了C#中System.Data.DataTable.LoadDataRow方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.LoadDataRow方法的具體用法?C# DataTable.LoadDataRow怎麽用?C# DataTable.LoadDataRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.LoadDataRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: aboutList
public static string aboutList()
{
StringBuilder strTxt = new StringBuilder();
DataTable tbl = new DataTable();
tbl.Columns.Add("Title", typeof(string));
tbl.Columns.Add("Url", typeof(string));
object[] aValues = { "公司簡介", "About.aspx" };
tbl.LoadDataRow(aValues, true);
object[] aValues1 = { "招聘信息", "Jobs.aspx" };
tbl.LoadDataRow(aValues1, true);
object[] aValues2 = { "站點地圖", "SiteMap.aspx" };
tbl.LoadDataRow(aValues2, true);
object[] aValues3 = { "聯係我們", "ContactInfo.aspx" };
tbl.LoadDataRow(aValues3, true);
if (tbl.Rows.Count > 0)
{
strTxt.Append("<dl>");
for (int j = 0; j < tbl.Rows.Count; j++)
{
DataRow dr2 = tbl.Rows[j];
strTxt.Append("<dd style=\"background-color: rgb(239,239,239); height: 26px;\">");
strTxt.Append("<a class=\"channelClass01\" href=\""+ dr2["Url"].ToString() +"\" style=\"position: relative;top: 5px; left: 15px;\">" + dr2["Title"].ToString() + "</a>");
strTxt.Append("</dd>");
}
strTxt.Append("</dl>");
}
else
strTxt.Append("暫無欄目!");
return strTxt.ToString();
}
示例2: CommasInDataDataTable
public static DataTable CommasInDataDataTable()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Columns.Add("Third");
dataTable.LoadDataRow(new object[] { "a,a", "b,b", "c,c" }, false);
dataTable.LoadDataRow(new object[] { "a1,a1", "b1,b1", "c1,c1" }, false);
return dataTable;
}
示例3: Main
static void Main(string[] args)
{
DataTable cave = new DataTable("Cave"); // création de la table "Cave" (vide pour l'instant)
DataColumn id = new DataColumn("ID");
id.DataType = typeof(int);
id.AutoIncrement = true; // active l'autoincrémentation de la colonne
id.AutoIncrementSeed = 1; // valeur de départ pour l'autoincrémentation
id.AutoIncrementStep = 1; // pas pour l'autoincrémentation
cave.Columns.Add(id);
cave.PrimaryKey = new DataColumn[] { id }; // désignation de la colonne "ID" comme clé primaire de la table
DataColumn vin = new DataColumn("Vin"); // création d'une colonne "Vin"
vin.DataType = typeof(string); // le type de données est string par défaut, cette ligne est donc optionelle
vin.Unique = true; // détermine si les valeurs de la colonnes doivent être uniques (false par défaut)
vin.AllowDBNull = false; // détermine si la colonne accepte les valeurs NULL (true par défaut)
vin.Caption = "Vin"; // nom que portera la colonne dans la représentation graphique (par défaut, c'est le nom de la colonne spécifié lors de la déclaration)
cave.Columns.Add(vin); // la colonne "Vin" est ajoutée à la table "Cave"
DataColumn annee = new DataColumn("Annee", typeof(int)); // on peut utiliser le constructeur à 2 paramètres pour déclarer une nouvelle colonne tout en spécifiant son type
annee.AllowDBNull = false;
annee.Caption = "Année";
cave.Columns.Add(annee);
DataColumn marque = new DataColumn("Marque");
marque.MaxLength = 35; // détermine la taille maximale dans le cas d'un string (-1 par défaut, càd illimité)
marque.AllowDBNull = false;
cave.Columns.Add(marque);
// la colonne suivante est une colonne dérivée des colonnes "Marque" et "Année"
DataColumn marqueEtAnnee = new DataColumn("MarqueEtAnnee");
marqueEtAnnee.MaxLength = 40;
marqueEtAnnee.Expression = "Annee + ' ' + Marque"; // la propriété "Expression" permet de concaténer les valeurs de plusieurs colonnes
marqueEtAnnee.Caption = "Marque et Année";
cave.Columns.Add(marqueEtAnnee);
// remplissage de la table
DataRow newCave = cave.NewRow(); // création de la ligne à insérer
newCave["Vin"] = "Beaujolais";
newCave["Marque"] = "Grand Cru";
newCave["Annee"] = 1982;
cave.Rows.Add(newCave); // ajout de la ligne à la table "Cave"
cave.LoadDataRow(new object[] { null, "Bourgogne", 2012, "Prix 2012" }, true); // une autre méthode d'ajout de lignes
cave.LoadDataRow(new object[] { null, "Saint-Emilion", 1983, "Cuvée Prestige" }, true);
cave.LoadDataRow(new object[] { null, "Pommard", 1959, "Clos Blanc" }, true);
printTable(cave);
}
示例4: GetRecord
public DataTable GetRecord()
{
FinesStyleInfoRequery finesStyleInfo = new FinesStyleInfoRequery();
IList iList=finesStyleInfo.FinesInfoRequery(null);
if (iList == null)
return null;
DataTable result = new DataTable();
if (iList.Count > 0)
{
PropertyInfo[] propertys = iList[0].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
result.Columns.Add(pi.Name, pi.PropertyType);
}
for (int i = 0; i < iList.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (PropertyInfo pi in propertys)
{
object obj = pi.GetValue(iList[i], null);
tempList.Add(obj);
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
}
示例5: getTable
private static DataTable getTable(string xmlTable_)
{
var doc = new System.Xml.XmlDocument();
doc.LoadXml(xmlTable_);
DataTable dt = new DataTable();
foreach (XmlNode rowNode in doc.DocumentElement.SelectNodes("./Table/Rows/Row"))
{
if (dt.Columns.Count == 0)
{
foreach (XmlNode node in rowNode.SelectNodes("./string"))
dt.Columns.Add(node.InnerText);
}
else
{
string[] vals = new string[dt.Columns.Count];
XmlNodeList list = rowNode.SelectNodes("./string");
for (int i = 0; i < list.Count; ++i)
vals[i] = list[i].InnerText;
dt.LoadDataRow(vals, true);
}
}
return dt;
}
示例6: GenerateLargeInputTable
private static DataTable GenerateLargeInputTable()
{
var sourceTable = new DataTable();
sourceTable.Columns.Add("BeginTime", typeof(DateTime));
sourceTable.Columns.Add("EndTime", typeof(DateTime));
sourceTable.Columns.Add("TravelTypeId", typeof(short));
for (var date = new DateTime(1000, 1, 1); date.Year <= 3000; date = date.AddDays(3))
{
sourceTable.LoadDataRow(new object[] { date.AddHours(8.0), date.AddHours(10.0), (short)0 }, LoadOption.OverwriteChanges);
sourceTable.LoadDataRow(new object[] { date.AddHours(17.0), date.AddHours(19.0), (short)1 }, LoadOption.OverwriteChanges);
sourceTable.LoadDataRow(new object[] { date.AddHours((24.0 * 2) + 17.0), date.AddHours((24.0 * 2) + 19.0), (short)2 }, LoadOption.OverwriteChanges);
}
return sourceTable;
}
示例7: 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);
}
}
示例8: ConvertToDataTable
private static DataTable ConvertToDataTable(object[] excelObjctData, string primaryKeyValue, string colsKeyValue)
{
Hashtable colsHash = ParseCols(colsKeyValue);
DataTable dt = new DataTable();
if (excelObjctData.Length > 0)
{
for (int i = 0; i < ((object[])excelObjctData[0]).Length; i++)
{
dt.Columns.Add(ToTagName(i));
}
foreach (object[] objs in excelObjctData)
{
if (objs[ToIndex(primaryKeyValue)] == null)
{
break;
}
dt.LoadDataRow(ParseColsType(objs, colsHash), true);
}
for (int i = 0; i < ((object[])excelObjctData[0]).Length; i++)
{
if (!colsHash.ContainsKey(ToTagName(i)))
{
dt.Columns.Remove(ToTagName(i));
}
}
}
return dt;
}
示例9: ToDataSet
/// <summary>
/// 集合裝換DataSet
/// </summary>
/// <param name="list">集合</param>
/// <returns></returns>
/// 2008-08-01 22:08 HPDV2806
public static DataSet ToDataSet(IList p_List)
{
DataSet result = new DataSet();
DataTable _DataTable = new DataTable();
if (p_List.Count > 0)
{
PropertyInfo[] propertys = p_List[0].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
_DataTable.Columns.Add(pi.Name, pi.PropertyType);
}
for (int i = 0; i < p_List.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (PropertyInfo pi in propertys)
{
object obj = pi.GetValue(p_List[i], null);
tempList.Add(obj);
}
object[] array = tempList.ToArray();
_DataTable.LoadDataRow(array, true);
}
}
result.Tables.Add(_DataTable);
return result;
}
示例10: 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;
}
示例11: 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;
}
示例12: load_from_excel_file
public void load_from_excel_file(string path, int bufferSize, out float[] channel_2, out float[] timeCoordinate, out int count_channel_2)
{
var workbook = ExcelLibrary.SpreadSheet.Workbook.Load(path);
var worksheet = workbook.Worksheets[0];
var cells = worksheet.Cells;
var dataTable = new DataTable("datatable");
// добавить столбцы в таблицу
dataTable.Columns.Add("force");
dataTable.Columns.Add("time");
// добавить строки в таблицу
for (int rowIndex = cells.FirstRowIndex + 1; rowIndex <= cells.LastRowIndex; rowIndex++)
{
var values = new List<string>();
foreach (var cell in cells.GetRow(rowIndex))
{
values.Add(cell.Value.StringValue);
}
dataTable.LoadDataRow(values.ToArray(), true);
}
DataRow[] dr = dataTable.Select();
channel_2 = new float[bufferSize];
timeCoordinate = new float[bufferSize];
count_channel_2 = 0;
foreach (DataRow r in dr)
{
channel_2[count_channel_2] = Int16.Parse((string)r[0]);
timeCoordinate[count_channel_2] = Single.Parse((string)r[1]);
count_channel_2++;
}
}
示例13: ListToDataTable
public static DataTable ListToDataTable(IList ResList)
{
DataTable TempDT = new DataTable();
System.Reflection.PropertyInfo[] p = ResList[0].GetType().GetProperties();
foreach (System.Reflection.PropertyInfo pi in p)
{
TempDT.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()));
}
for (int i = 0; i < ResList.Count; i++)
{
IList TempList = new ArrayList();
foreach (System.Reflection.PropertyInfo pi in p)
{
object oo = pi.GetValue(ResList[i], null);
TempList.Add(oo);
}
object[] itm = new object[p.Length];
for (int j = 0; j < TempList.Count; j++)
{
itm.SetValue(TempList[j], j);
}
TempDT.LoadDataRow(itm, true);
}
return TempDT;
}
示例14: Create
public void Create(ConstructGen<double> candleData_, int openIndex_ = 0, int highIndex_ = 1, int lowIndex_ = 2, int closeIndex_ = 3, int setupLength_=9, int countdownLength_=13)
{
var dt = new DataTable();
dt.Rows.Clear();
dt.Columns.Clear();
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Open", typeof(double));
dt.Columns.Add("High", typeof(double));
dt.Columns.Add("Low", typeof(double));
dt.Columns.Add("Close", typeof(double));
dt.Columns.Add("Volume", typeof(double));
ultraChart1.DataSource = dt;
var closes = candleData_.GetColumnValuesAsDDC(closeIndex_);
var range = closes.Data.Max() - closes.Data.Min();
var cellHeight = range/10d;
var setupStarts = DeMarkAnalysis.GetSetups(candleData_,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_);
DeMarkAnalysis.AddCountdowns(candleData_, setupStarts,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_,countdownLength_);
for (int i = 0; i < candleData_.Dates.Count; ++i)
{
var date = candleData_.Dates[i];
var arr = candleData_.GetValues(date);
dt.LoadDataRow(new object[]
{
date,
arr[openIndex_],
arr[highIndex_],
arr[lowIndex_],
arr[closeIndex_],
0d
}, true);
foreach(var mark in setupStarts)
{
addAnnotations(date, mark, i, cellHeight, arr,openIndex_,highIndex_,lowIndex_,closeIndex_);
}
}
EstablishDefaultTooltip(hash =>
{
int rowNumber = (int) hash["DATA_ROW"];
return string.Format("{0} Open: {1}, High: {2}, Low: {3}, Close: {4}",
((DateTime) dt.Rows[rowNumber]["Date"]).ToString("dd-MMM-yyyy"),
((double) dt.Rows[rowNumber]["Open"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["High"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["Low"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["Close"]).ToString(CultureInfo.InvariantCulture)
).Replace(",", System.Environment.NewLine);
});
}
示例15: SimpleDataTable
public static DataTable SimpleDataTable()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("2nd");
dataTable.Columns.Add("3");
dataTable.LoadDataRow(new object[] { "a", "b", "c" }, false);
return dataTable;
}