本文整理汇总了C#中DataRow.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.Add方法的具体用法?C# DataRow.Add怎么用?C# DataRow.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataRow
的用法示例。
在下文中一共展示了DataRow.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitNormalizedScaleRow
private DataRow InitNormalizedScaleRow(ScaleType scaleType, int maxCount) {
var scaleRow = new DataRow {ScaleType = scaleType};
for (var i = 0; i < maxCount; i++) {
scaleRow.Add(new DataItem {
NegMin = 0 != (Preferences.SeriaCalcMode & SeriaCalcMode.CrossSeriaSum) ? 0 : decimal.MaxValue,
PosMax = 0 != (Preferences.SeriaCalcMode & SeriaCalcMode.CrossSeriaSum) ? 0 : decimal.MinValue,
PosMin = decimal.MaxValue,
NegMax = decimal.MinValue
});
}
return scaleRow;
}
示例2: ReadXLS
public DataTable ReadXLS(string sheetName = "" )
{
Debug.Log("Begin to read " + sheetName + " form " + fileName);
TextAsset xmlData = new TextAsset();
xmlData = (TextAsset)Resources.Load(fileName, typeof(TextAsset));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlData.text);
DataTable res = new DataTable();
//Get sheet by sheetName
XmlNodeList sheets = xmlDoc.GetElementsByTagName("Worksheet");
XmlNode sheet = null;
foreach (XmlNode s in sheets)
{
if (s.Attributes["ss:Name"].Value == sheetName)
{
sheet = s;
}
}
if (sheet == null )
{
Debug.Log("Cannot find sheet " + sheetName);
return res;
}
//Analyze the sheet
// xmlDoc.LoadXml(sheet.InnerXml);
XmlNode sheetContent = sheet.ChildNodes[0];
for(int i = sheetContent.ChildNodes.Count - 1 ; i >= 0 ; --i)
{
// Debug.Log(sheetContent.ChildNodes[i].LocalName);
if ( sheetContent.ChildNodes[i].LocalName != "Row" )
sheetContent.RemoveChild(sheetContent.ChildNodes[i]);
}
// XmlNodeList rows = xmlDoc.GetElementsByTagName("Row");
XmlNodeList rows = sheetContent.ChildNodes;
var firstLineDic = new Dictionary<string,string>();
// xmlDoc.LoadXml(rows[0].InnerXml);
XmlNodeList firstLine = rows[0].ChildNodes;
for(int i = 0 ; i < firstLine.Count ; ++ i )
{
firstLineDic.Add((i+1).ToString(), firstLine[i].InnerText);
res.AddFirst(firstLine[i].InnerText);
// Debug.Log("First Line " + firstLine[i].InnerText);
}
for(int i = 1 ; i < rows.Count ; ++i )
// for( int i = 1 ; i < 3 ; ++ i )
{
// xmlDoc.LoadXml(rows[i].InnerXml);
// XmlNodeList cells = xmlDoc.GetElementsByTagName("Cell",rows[i].NamespaceURI);
XmlNodeList cells = rows[i].ChildNodes;
DataRow r = new DataRow();
int indexNow = 1;
for(int j = 0 ; j < cells.Count ; ++ j )
// for( int j = 0 ; j < 3 ; ++ j)
{
if (cells[j].Attributes["ss:Index"] != null)
{
indexNow = int.Parse( cells[j].Attributes["ss:Index"].Value);
}
if (cells[j].InnerText != "" )
r.Add(firstLineDic[indexNow.ToString()],cells[j].InnerText);
indexNow ++;
}
string key = "";
if (!r.isBlank(firstLineDic["1"]))
key = r.Select(firstLineDic["1"]);
res.AddRow( key, r);
}
Debug.Log("rows " + rows.Count.ToString());
return res;
}
示例3: GetCurrentValuesSingleRow
private static bool GetCurrentValuesSingleRow(int targetId, MetricGroup metricGroup, string[] metrics, out DataRow data)
{
data = null;
object[] values = null;
CacheTable cache = null;
// Do not load data from repository if it has not been done yet. This means no current stats are available yet.
if (metricGroup.isCumulative)
{
if (ContainsKey(GetCacheKey(-1, metricGroup)))
cache = _cache[GetCacheKey(-1, metricGroup)];
}
else
{
if (ContainsKey(GetCacheKey(targetId, metricGroup)))
cache = _cache[GetCacheKey(targetId, metricGroup)];
}
data = new DataRow();
// get values by key (targetId)
if (cache != null)
{
int id = cache.GetIdByKey(new object[] { (object)targetId });
if (id != -1)
values = cache[id];
}
if (values == null)
{
foreach (string metricName in metrics)
data.Add(metricName, new DataValue(metricGroup[metricName].type, null));
return false;
}
foreach (string metricName in metrics)
{
data.Add(metricName,
new DataValue(cache.GetColumnMetadataByName(metricName).type,
values[cache.GetValueColumnIdByName(metricName) + 1]
)
);
}
return true;
}