本文整理汇总了C#中System.Data.DataView.ToTable方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.ToTable方法的具体用法?C# DataView.ToTable怎么用?C# DataView.ToTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataView
的用法示例。
在下文中一共展示了DataView.ToTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAllShef
private void AddAllShef(DataTable dTab, string shefFile)
{
// Get Locations
DataView view = new DataView(dTab);
DataTable distinctLocations = view.ToTable(true, "location");
foreach (DataRow locationItem in distinctLocations.Rows)
{
string shefLocation = locationItem["location"].ToString();
// Get location-pcode pairs
DataTable distinctPairs = view.ToTable(true, "location", "shefcode");
var distinctCodes = new DataView(distinctPairs);
distinctCodes.RowFilter = "location = '" + shefLocation + "'";
// Get Pcodes
var codeTable = distinctCodes.ToTable();
foreach (DataRow codeItem in codeTable.Rows)
{
string shefCode = codeItem["shefcode"].ToString();
// Add Series
var s = new ShefSeries(shefLocation, shefCode, shefFile);
var valTable = dTab.Select(string.Format("location = '{0}' AND shefcode = '{1}'", shefLocation, shefCode));
foreach (DataRow item in valTable)
{
s.Add(DateTime.Parse(item["datetime"].ToString()), Convert.ToDouble(item["value"]));
}
DB.AddSeries(s, CurrentFolder);
}
}
}
示例2: Form_ClosingAccount_Load
private void Form_ClosingAccount_Load(object sender, EventArgs e)
{
ds.Tables.Clear();
ds.Tables.Add(GetData.getbal()); //0
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = "sub_type = '收入'";
ds.Tables.Add(dv.ToTable("in")); //1
dv.RowFilter = "sub_type = '支出'";
ds.Tables.Add(dv.ToTable("out")); //2
//顯示收入
dgv_profit.DataSource = ds.Tables[1];
dgv_profit.Columns[1].Visible = false;
dgv_profit.Columns[0].HeaderText = "科目名稱";
dgv_profit.Columns[2].HeaderText = "餘額";
dgv_profit.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
//顯示支出
dgv_loss.DataSource = ds.Tables[2];
dgv_loss.Columns[1].Visible = false;
dgv_loss.Columns[0].HeaderText = "科目名稱";
dgv_loss.Columns[2].HeaderText = "餘額";
dgv_loss.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dgv_loss.AutoResizeColumns();
dgv_loss.AutoResizeColumns();
Balance_count();
}
示例3: btn_show_Click
//依照選擇的年分與季別顯示報表
private void btn_show_Click(object sender, EventArgs e)
{
string md_start = "0101"; //開始月日
string md_end = "1231"; //結束月日
//擷取自行選擇的整年份資料
string start = nud_year.Value.ToString().Trim() + md_start.Trim(); //開始擷取年月日
string end = nud_year.Value.ToString().Trim() + md_end.Trim(); //結束擷取年月日
total.Tables.Clear();
total.Tables.Add(GetData.getbal(start, end)); //table 0
dv = new DataView(total.Tables[0], "sub_type = '資產' ", "sub_name", DataViewRowState.CurrentRows);
total.Tables.Add(dv.ToTable("Assets")); //table 1 資產類
dv.RowFilter = "sub_type = '負債' ";
total.Tables.Add(dv.ToTable("Liabilities")); //table 2 負債類
dv.RowFilter = "sub_type = '淨值' ";
total.Tables.Add(dv.ToTable("Net")); //table 3 淨值類
//設定ListView格式
lv_Assets.Clear();
lv_Liabilities.Clear();
lv_Net.Clear();
lv_Assets.Columns.Add("名稱");
lv_Assets.Columns.Add("餘額");
lv_Liabilities.Columns.Add("名稱");
lv_Liabilities.Columns.Add("餘額");
lv_Net.Columns.Add("名稱");
lv_Net.Columns.Add("餘額");
lv_Assets.View = View.Details;
lv_Liabilities.View = View.Details;
lv_Net.View = View.Details;
//顯示資產清單
foreach (DataRow row in total.Tables[1].Rows)
{
ListViewItem item = new ListViewItem(row[0].ToString());
item.SubItems.Add(row[2].ToString());
lv_Assets.Items.Add(item);
}
//顯示負債清單
foreach (DataRow row in total.Tables[2].Rows)
{
ListViewItem item = new ListViewItem(row[0].ToString());
item.SubItems.Add(row[2].ToString());
lv_Liabilities.Items.Add(item);
}
//顯示淨值清單
foreach (DataRow row in total.Tables[3].Rows)
{
ListViewItem item = new ListViewItem(row[0].ToString());
item.SubItems.Add(row[2].ToString());
lv_Net.Items.Add(item);
}
lv_Assets.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
lv_Liabilities.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
lv_Net.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
btn_printout.Enabled = true;
}
示例4: Extract
public override System.Data.DataTable Extract(UnitType source, int year, int id, string column,
bool addTimeColumn = false, bool forValidation = true)
{
if (source == UnitType.WATER)
throw new Exception("ExtractSWAT_Text_Database doesn't support " + source.ToString());
DataTable finalTable = null;
//if (_interval == OutputIntervalType.DAY && source == UnitType.HRU) //record-by-record reading for daily HRU outputs to avoid out of memory
//{
// finalTable = extractDailyHRU(column);
//}
//else
//{
//read the whole table if necessary
DataTable wholeTable = getWholeTable(source, year != -1);
DateTime startTime = DateTime.Now;
_extractTime = -99.0;
//select the request data from the whole table
//Console.WriteLine(string.Format("Query data for {0}_{1}_{2}", source,id,column));
DataView view = new DataView(wholeTable);
string filter = "";
if (id > 0) filter = string.Format("{0} = {1}", source, id); //filter for certain id and remove the year summary,this is not good for yearly output
if (_interval == OutputIntervalType.DAY || _interval == OutputIntervalType.MON)
{
if (!string.IsNullOrWhiteSpace(filter)) filter += " and ";
filter += COLUMN_NAME_MON_SWAT + " <= 366";
}
if (year != -1)
{
if (!string.IsNullOrWhiteSpace(filter)) filter += " and ";
filter += string.Format("{0} >= #{1}-01-01# and {0} < #{2}-01-01#", COLUMN_NAME_TIME, year,year + 1);
}
view.RowFilter = filter;
string timeCol = COLUMN_NAME_MON_SWAT;
DataTable queryTable = null;
if (id > 0)
queryTable = view.ToTable(false, new string[] { timeCol, column }); //time and value
else
queryTable = view.ToTable(false, new string[] { timeCol, source.ToString(), column }); //output id when all ids is outputs
finalTable = queryTable;
if (finalTable == null || finalTable.Rows.Count == 0)
throw new Exception("No results!");
//add time if necessary
//don't do this on the whole dataset any more
if (addTimeColumn && year == -1) calculateDate(finalTable);
//}
_extractTime = DateTime.Now.Subtract(startTime).TotalMilliseconds;
return finalTable;
}
示例5: btn_show_Click
//顯示結果
private void btn_show_Click(object sender, EventArgs e)
{
string md_start = "0101"; //開始月日
string md_end = "1231"; //結束月日
//擷取自行選擇的年分
string start = nud_year.Value.ToString().Trim() + md_start.Trim(); //開始擷取年月日
string end = nud_year.Value.ToString().Trim() + md_end.Trim(); //結束擷取年月日
ds.Tables.Clear();
ds.Tables.Add(GetData.getbal(start, end)); //table 0
DataView dv = new DataView(ds.Tables[0], "sub_type = '收入'", "sub_name", DataViewRowState.CurrentRows);
ds.Tables.Add(dv.ToTable("profit")); //table 1
dv.RowFilter = "sub_type = '支出'";
ds.Tables.Add(dv.ToTable("loss")); //table 2
//設定ListView格式
lv_profit.Clear();
lv_loss.Clear();
lv_profit.Columns.Add("名稱");
lv_profit.Columns.Add("餘額");
lv_loss.Columns.Add("名稱");
lv_loss.Columns.Add("餘額");
lv_profit.View = View.Details;
lv_loss.View = View.Details;
//顯示收入
foreach (DataRow row in ds.Tables[1].Rows)
{
ListViewItem item = new ListViewItem(row[0].ToString());
item.SubItems.Add(row[2].ToString());
lv_profit.Items.Add(item);
}
//顯示支出
foreach (DataRow row in ds.Tables[2].Rows)
{
ListViewItem item = new ListViewItem(row[0].ToString());
item.SubItems.Add(row[2].ToString());
lv_loss.Items.Add(item);
}
//調整欄寬
lv_profit.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
lv_loss.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
//計算餘額
object sum_profit = ds.Tables[1].Compute("Sum(balance)", ""); // 收入總和
object sum_loss = ds.Tables[2].Compute("Sum(balance)", ""); // 支出總和
if (string.IsNullOrEmpty(sum_profit.ToString())) sum_profit = 0;
if (string.IsNullOrEmpty(sum_loss.ToString())) sum_loss = 0;
decimal total = Convert.ToDecimal(sum_profit) - Convert.ToDecimal(sum_loss);
txt_total.Text = total.ToString();
btn_printout.Enabled = true;
}
示例6: ConstructFilterExpression
private String ConstructFilterExpression(DataView view, GridSearch args)
{
String format = ((view.ToTable().Columns[args.SearchColumn].DataType == typeof(String)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime))) ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}";
String text2 = "[{0}] {1} ({2})";
String text3 = "[{0}] LIKE '{1}'";
String text4 = "[{0}] NOT LIKE '{1}'";
switch (args.SearchOperation)
{
case SearchOperation.IsEqualTo:
return String.Format(format, args.SearchColumn, "=", args.SearchString);
case SearchOperation.IsLessThan:
return String.Format(format, args.SearchColumn, "<", args.SearchString);
case SearchOperation.IsLessOrEqualTo:
return String.Format(format, args.SearchColumn, "<=", args.SearchString);
case SearchOperation.IsGreaterThan:
return String.Format(format, args.SearchColumn, ">", args.SearchString);
case SearchOperation.IsGreaterOrEqualTo:
return String.Format(format, args.SearchColumn, ">=", args.SearchString);
case SearchOperation.IsIn:
return String.Format(text2, args.SearchColumn, "in", args.SearchString);
case SearchOperation.IsNotIn:
return String.Format(text2, args.SearchColumn, "not in", args.SearchString);
case SearchOperation.BeginsWith:
return String.Format(text3, args.SearchColumn, args.SearchString + "%");
case SearchOperation.DoesNotBeginWith:
return String.Format(text4, args.SearchColumn, args.SearchString + "%");
case SearchOperation.EndsWith:
return String.Format(text3, args.SearchColumn, "%" + args.SearchString);
case SearchOperation.DoesNotEndWith:
return String.Format(text4, args.SearchColumn, "%" + args.SearchString);
case SearchOperation.Contains:
return String.Format(text3, args.SearchColumn, "%" + args.SearchString + "%");
case SearchOperation.DoesNotContain:
return String.Format(text4, args.SearchColumn, "%" + args.SearchString + "%");
}
throw new Exception("Invalid search operation.");
}
示例7: GroupBy
public DataTable GroupBy(string[] i_sGroupByColumns, string i_sAggregateColumn, DataTable i_dSourceTable, double NoDV, double upBnd , double lowBnd)
{
DataView dv = new DataView(i_dSourceTable);
//getting distinct values for group column
DataTable dtGroup = dv.ToTable(true, new string[] { i_sGroupByColumns[0], i_sGroupByColumns[1], i_sGroupByColumns[2], });
//adding column for the row count
dtGroup.Columns.Add("DateTime", typeof(DateTime));
dtGroup.Columns.Add("DataValue", typeof(double));
//looping thru distinct values for the group, counting
foreach (DataRow dr in dtGroup.Rows)
{
string filter = i_sGroupByColumns[0] + " = '" + dr[i_sGroupByColumns[0]] + "' AND " + i_sGroupByColumns[1] + " = '" + dr[i_sGroupByColumns[1]] + "' AND " + i_sGroupByColumns[2] + " = '" + dr[i_sGroupByColumns[2]] + "' AND DataValue <>" + NoDV.ToString() + " AND DataValue <" + upBnd + " AND DataValue > " + lowBnd;
// foreach (string column in i_sGroupByColumns
object value = i_dSourceTable.Compute("AVG(" + i_sAggregateColumn + ")", filter);
object date = i_dSourceTable.Compute("MIN(LocalDateTime)", filter);
dr["DataValue"] = value;//==DBNull.Value ? DBNull.Value : value;
dr["DateTime"] = value == DBNull.Value ? new DateTime((int)dr["Year"], (int)dr["Month"], (int)dr["Day"]) : date;
}
//returning grouped/counted result
return dtGroup;
}
示例8: btnSearchWines_Click
private void btnSearchWines_Click(object sender, RoutedEventArgs e)
{
// luetaan koko XML DataSettiin
// DataSet in-memory database
try
{
string file = @"D:\H3340\Viinit1.xml";
ds = new DataSet();
dt = new DataTable();
dv = new DataView();
ds.ReadXml(file);
dt = ds.Tables[0]; // voisi viitata myös taulun nimellä. nyt satutaan tietämään että tiedostossa on vain yksi taulu
dv = dt.DefaultView;
dgWines.ItemsSource = dv;
// haetaan maat comboon
maat = new List<string>();
dv.ToTable("UniqueData", false, "maa");
}
catch (Exception ex)
{
throw;
}
}
示例9: filterDataview
/// <summary>
/// To search menu details by different conditions
/// </summary>
/// <param name="DvMenu"></param>
/// <param name="Column"></param>
/// <param name="Operator"></param>
/// <param name="Value"></param>
public void filterDataview(DataView DvMenu, string Column, string Operator, string Value)
{
DvMenu.RowFilter = Column + " " + Operator + "'" + Value + "'";
if (DvMenu.ToTable().Rows.Count == 0)
{
MsgMenu.Msg = "Record(s) not found";
MsgMenu.showmsg();
ViewState["DtMenu"] = DvMenu.ToTable();
BindGrid(DvMenu.ToTable());
}
else
{
ViewState["DtMenu"] = DvMenu.ToTable();
BindGrid(DvMenu.ToTable());
}
}
示例10: deWeight
private static DataTable deWeight(DataTable _dt, string _col)
{
DataTable dt = _dt;
DataView dv = new DataView(dt);
DataTable dt2 = dv.ToTable(true, _col);
return dt2;
}
示例11: CheckStatusAndProcessData
public void CheckStatusAndProcessData()
{
DataTable dtGL_Master = new SCMSRepository().GetGL_VchrMastersData();
DataTable dtGL_Details = new SCMSRepository().GetGL_VchrDetailsData();
if (dtGL_Master != null && dtGL_Master.Rows.Count > 0)
{
// ExportVouchersDataToXML(dtGL_Master, dtGL_Details);
foreach (DataRow drow in dtGL_Master.Rows)
{
int VchMas_Id = Convert.ToInt32(drow["VchMas_Id"]);
new SCMSRepository().SaveOrUpdateGL_VchrMaster(drow);
DataView dv_Vsdetail = new DataView(dtGL_Details , "VchMas_Id=" + VchMas_Id, "", DataViewRowState.CurrentRows);
DataTable dtFilteredData = dv_Vsdetail.ToTable();
if (dtFilteredData != null && dtFilteredData.Rows.Count > 0)
{
foreach (DataRow dtrow in dtFilteredData.Rows)
{
new SCMSRepository().SaveGL_VchrDetails(dtrow);
}
}
}
}
}
示例12: ReloadLBSentences
private int ReloadLBSentences(bool limit)
{
if (dataGridView_Logs.CurrentRow == null || dataGridView_Logs.CurrentRow.DataBoundItem == null)
return -1;
DataView dv = new DataView(dt_logs);
dv.RowStateFilter = DataViewRowState.CurrentRows;
string rf = "log_id <> '" + dataGridView_Logs.CurrentRow.Cells["LOG_ID"].Value + "'";
string col = null;
switch (rtb_active.Name)
{
case "richTextBox_GroupCheck": col = "COMMENTS_GROUP"; break;
case "richTextBox_TimeCheck": col = "COMMENTS_TIME"; break;
case "richTextBox_LogCheck": col = "COMMENTS_LOG"; break;
case "richTextBox_GraphCheck": col = "COMMENTS_GRAPH"; break;
case "richTextBox_GSetComments": col = "COMMENTS_GSET"; break;
}
rf += " and " + col + " is not null and trim(" + col + ") <> ''";
if (limit)
{
rf += " and ab_type_name = '" + dataGridView_Logs.CurrentRow.Cells["AB_TYPE_NAME"].Value + "'";
}
dv.RowFilter = rf;
listBox_Sentences.DataSource = dv.ToTable(true, new string[] { col });
listBox_Sentences.DisplayMember = col;
listBox_Sentences.ValueMember = col;
listBox_Sentences.SelectedIndex = -1;
return dv.Count;
}
示例13: SortDesc
private DataTable SortDesc(DataTable dt,string sortfield)
{
DataView dv = new DataView();
dv.Table = dt;
dv.Sort = sortfield;
return dv.ToTable();
}
示例14: LoadListData
private void LoadListData(string AFilter)
{
string CheckedMember = "CHECKED";
string ValueMember = PUnitTable.GetPartnerKeyDBName();
string DisplayMember = PUnitTable.GetUnitNameDBName();
PUnitTable Table;
// retrieve data from server
Table = TRemote.MPartner.Partner.WebConnectors.GetLedgerUnits(AFilter);
DataView view = new DataView(Table);
DataTable NewTable = view.ToTable(true, new string[] { ValueMember, DisplayMember });
NewTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
clbLedger.Columns.Clear();
clbLedger.AddCheckBoxColumn("", NewTable.Columns[CheckedMember], 17, false);
clbLedger.AddTextColumn(Catalog.GetString("Ledger Name"), NewTable.Columns[DisplayMember], 240);
clbLedger.AddPartnerKeyColumn(Catalog.GetString("Partner Key"), NewTable.Columns[ValueMember], 100);
clbLedger.DataBindGrid(NewTable, DisplayMember, CheckedMember, ValueMember, false, true, false);
// allow 'any' selection for receipt frequency
DataRow emptyRow = cmbReceiptLetterFrequency.Table.NewRow();
emptyRow[0] = string.Empty;
emptyRow[1] = Catalog.GetString("Any Frequency");
cmbReceiptLetterFrequency.Table.Rows.Add(emptyRow);
}
示例15: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
PnVistor.Visible = false;
PnStudent.Visible = false;
PnTeacher.Visible = false;
PnAdmin.Visible = false;
if (UserIdentity.IsInRole(UserIdentity.Role.Admin))
{
PnAdmin.Visible = true;
btEdit.Visible = true;
}
else if (UserIdentity.IsInRole(UserIdentity.Role.Student))
{
PnStudent.Visible = true;
btEdit.Visible = false;
}
else if (UserIdentity.IsInRole(UserIdentity.Role.Teacher))
{
PnTeacher.Visible = true;
btEdit.Visible = true;
}
else
{
PnVistor.Visible = true; ;
btEdit.Visible = false;
}
data = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());
if (data.Count == 0)
content = "无内容";
else
content = data.ToTable().Rows[0][0].ToString();
DataBind();
}