本文整理匯總了C#中System.Data.DataTable.Copy方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.Copy方法的具體用法?C# DataTable.Copy怎麽用?C# DataTable.Copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.Copy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InitialOriginTable
private void InitialOriginTable(DataTable dt)
{
originalTable = dt.Copy();
originalTable.Columns.Add("PassengerName");
originalTable.Columns["PassengerName"].SetOrdinal(0);
originalTable.Columns.Add("FlightInfo");
originalTable.Columns["FlightInfo"].SetOrdinal(1);
originalTable.Columns.Add("StaffName");
//originalTable.Columns["StaffName"].SetOrdinal(2);
foreach (DataRow row in originalTable.Rows)
{
Guid passengerID = Guid.Parse(row["PassengerID"].ToString());
Passenger passenger = reservationSystem.GetPassengerByID(passengerID);
string passengerName = passenger.firstName + " " + passenger.lastName;
row["PassengerName"] = passengerName;
Guid staffID = Guid.Parse(row["StaffID"].ToString());
Staff staff = reservationSystem.GetStaffByID(staffID);
string staffName = staff.firstName + " " + staff.lastName;
row["StaffName"] = staffName;
Guid flightID = Guid.Parse(row["FlightID"].ToString());
Flight flight = reservationSystem.GetFlightByID(flightID);
string flightInfo = flight.origin.name + " - " + flight.destination.name;
row["FlightInfo"] = flightInfo;
}
}
示例2: SortDataTable
/// <summary>
/// Sorts the <see cref="System.Data.DataTable"/>.
/// </summary>
/// <param name="sourceTable">The source table.</param>
/// <param name="sortColumn">The column to sort by.</param>
/// <param name="order">The <see cref="Tools.Common.SortOrder"/>.</param>
/// <param name="copyIfNoSort">Should only be true when one table owner is assumed
/// other time and space.</param>
/// <returns></returns>
public static DataTable SortDataTable(DataTable sourceTable, string sortColumn, SortOrder order, bool copyIfNoSort)
{
if (String.IsNullOrEmpty(sortColumn))
{
// copyIfNoSort make the semantic more stable, even if there is no sort required
// the copy is returned, so the caller may assume same level of independence.
if (copyIfNoSort) return sourceTable.Copy();
return sourceTable;
}
DataTable targetTable = sourceTable.Clone();
DataRow[] sourceRows = sourceTable.Select(null,
("[" + sortColumn + "] " + order.ToString()).TrimEnd(' '));
for (int i = 0; i < sourceRows.Length; i++)
{
DataRow newRow = targetTable.NewRow();
newRow.ItemArray = sourceRows[i].ItemArray;
targetTable.Rows.Add(newRow);
}
return targetTable;
}
示例3: GetPagedTable
public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
{
if (PageIndex == 0)
return dt;
DataTable newdt = dt.Copy();
newdt.Clear();
int rowbegin = (PageIndex - 1) * PageSize;
int rowend = PageIndex * PageSize;
if (rowbegin >= dt.Rows.Count)
return newdt;
if (rowend > dt.Rows.Count)
rowend = dt.Rows.Count;
for (int i = rowbegin; i <= rowend - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
GridView grid = new GridView();
DataTable dt = new DataTable();
List<Terceiro> lista = new List<Terceiro>();
TerceiroBL tbl = new TerceiroBL();
lista = tbl.buscaTerceiros(Convert.ToInt16(Session["empresa"].ToString()));
DataColumn c1 = new DataColumn("Cnpj", Type.GetType("System.String"));
DataColumn c2 = new DataColumn("Nome", Type.GetType("System.String"));
DataColumn c3 = new DataColumn("Email", Type.GetType("System.String"));
DataColumn c4 = new DataColumn("Telefone", Type.GetType("System.String"));
DataColumn c5 = new DataColumn("editar", Type.GetType("System.String"));
dt.Columns.Add(c1);
dt.Columns.Add(c2);
dt.Columns.Add(c3);
dt.Columns.Add(c4);
dt.Columns.Add(c5);
foreach (Terceiro t in lista)
{
DataRow dr = dt.NewRow();
dr["Cnpj"] = t.cpfCnpj.ToString();
dr["Nome"] = t.nome.ToString();
dr["Email"] = t.email.ToString();
dr["Telefone"] = t.telefone.ToString();
dr["editar"] = "~/EditaTerceiro.aspx?id_terceiro=" + t.id.ToString();
dt.Rows.Add(dr);
}
gridTerceiros.DataSource = dt.Copy();
gridTerceiros.DataBind();
}
示例5: saveConfig
/// <summary>
/// Saves a copy of the ProxyTable in the application settings
/// </summary>
/// <param name="proxyTable">DataTable to save</param>
public static void saveConfig(DataTable proxyTable)
{
DataTable copyTable = proxyTable.Copy();
SwitchProxy.Properties.Settings.Default.ProxyTable = null;
SwitchProxy.Properties.Settings.Default.ProxyTable = copyTable;
SwitchProxy.Properties.Settings.Default.Save();
}
示例6: NW_Dhcp_Customer_Getlist_MySQL
//////////////////////////////////////////MySQL
public void NW_Dhcp_Customer_Getlist_MySQL()
{
string sql = "Select * from NW_Dhcp_Customer";
dt = Class.MySqlConnect.ExecQuery(sql);
gridItem.DataSource = dt;
dtIpPublic = dt.Copy();
}
示例7: SerializePart
public void SerializePart( DataTable data )
{
// TODO: ТОЛЬКО ДЛЯ ТЕСТИРОВАНИЯ. УБРАТЬ!
// data.TableName += Guid.NewGuid().ToString();
ResultDataSet.Tables.Add( data.Copy() );
}
示例8: getTopCategoryTotals
public static DataTable getTopCategoryTotals(DataTable inputTable, int topRowsCount)
{
DataTable table = inputTable.Copy();
table.Clear();
double otherTotal = 0;
try
{
for (int i = 0; i < inputTable.Rows.Count; i++)
{
if (i > topRowsCount - 1)
{
otherTotal = otherTotal + double.Parse(inputTable.Rows[i]["total"].ToString());
}
else
{
table.Rows.Add(inputTable.Rows[i][0], inputTable.Rows[i][1]);
}
}
if (inputTable.Rows.Count>5)
{
table.Rows.Add("Other", otherTotal);
}
}
catch (Exception exception)
{
Logger.LogException(exception);
Helper.showMessage("Unable to trim top category totals from database. \n\n " + exception.ToString());
}
return table;
}
示例9: dataGridView1_CellClick
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "exe")
{//打開文件
openFileDialog1.ShowDialog();
dataGridView1.CurrentCell.Value = openFileDialog1.FileName;
}
else if (dataGridView1.Columns[e.ColumnIndex].Name == "ok")
{//保存文件
DataTable _dt = new DataTable();
_dt.Columns.Add("exe");
_dt.Columns.Add("message");
_dt.Columns.Add("rule");
foreach (DataGridViewRow var in dataGridView1.Rows)
{
if (var.Cells[1].Value == null)
{
continue;
}
_dt.Rows.Add(var.Cells["exe"].Value.ToString(), var.Cells["message"].Value.ToString() == null ? "*" : var.Cells["message"].Value.ToString(), var.Cells["rule"].Value.ToString() == null ? "1" : var.Cells["rule"].Value.ToString());
}
DataSet _ds = new DataSet();
_ds.Tables.Add(_dt.Copy());
SaveData(_ds);
}
}
示例10: AddGRAlarm
/// <summary>
///
/// </summary>
/// <param name="tbl"></param>
public void AddGRAlarm(DataTable tbl)
{
DataTable s = this.dataGridView1.DataSource as DataTable;
if (s == null)
{
s = tbl.Copy();
this.dataGridView1.DataSource = s;
}
else
{
s.Merge(tbl);
}
if (dataGridView1.Rows.Count > 0)
{
// remove records
//
if (dataGridView1.Rows.Count > Config.Default.GRAlarmMaxCount)
{
int n = dataGridView1.Rows.Count - Config.Default.GRAlarmMaxCount;
for (int i = 0; i < n; i++)
{
dataGridView1.Rows.RemoveAt(0);
//s.Rows[0].Delete();
}
}
// move to last record
//
DataGridViewCell lastCell = this.dataGridView1[0, this.dataGridView1.Rows.Count - 1];
this.dataGridView1.CurrentCell = lastCell;
}
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
GridView grid = new GridView();
DataTable dt = new DataTable();
List<Usuario> lista = new List<Usuario>();
UsuarioBL uBL = new UsuarioBL();
lista = uBL.buscaUsuariosEmpresa(Convert.ToInt16(Session["empresa"].ToString()));
DataColumn c1 = new DataColumn("Email", Type.GetType("System.String"));
DataColumn c2 = new DataColumn("Nome", Type.GetType("System.String"));
DataColumn c3 = new DataColumn("Empresa", Type.GetType("System.String"));
DataColumn c4 = new DataColumn("Licença", Type.GetType("System.String"));
DataColumn c5 = new DataColumn("editar", Type.GetType("System.String"));
dt.Columns.Add(c1);
dt.Columns.Add(c2);
dt.Columns.Add(c3);
dt.Columns.Add(c4);
dt.Columns.Add(c5);
foreach (Usuario u in lista)
{
DataRow dr = dt.NewRow();
dr["Email"] = u.email.ToString();
dr["Nome"] = u.nome.ToString();
dr["Empresa"] = u.idEmpresa.ToString();
dr["Licença"] = u.dataFimLicenca.ToShortDateString();
dr["editar"] = "~/EditarUsuario.aspx?user_mail=" + u.email.ToString();
dt.Rows.Add(dr);
}
gridUsuarios.DataSource = dt.Copy();
gridUsuarios.DataBind();
}
示例12: alimentagrid
public void alimentagrid()
{
GridView grid = new GridView();
DataTable dt = new DataTable();
List<Etapa> lista = new List<Etapa>();
EtapaBL ebl = new EtapaBL();
lista = ebl.buscaEtapas();
DataColumn c1 = new DataColumn("id", Type.GetType("System.String"));
DataColumn c2 = new DataColumn("nome", Type.GetType("System.String"));
DataColumn c3 = new DataColumn("editar", Type.GetType("System.String"));
dt.Columns.Add(c1);
dt.Columns.Add(c2);
dt.Columns.Add(c3);
foreach (Etapa e in lista)
{
DataRow dr = dt.NewRow();
dr["id"] = e.id.ToString();
dr["nome"] = e.tituloEtapa.ToString();
dr["editar"] = "~/EditaEtapa.aspx?id_etapa=" + e.id.ToString();
dt.Rows.Add(dr);
}
griEtapas.DataSource = dt.Copy();
griEtapas.DataBind();
}
示例13: carregaTabela
public void carregaTabela()
{
GridView grid = new GridView();
DataTable dt = new DataTable();
List<ItemTarefa> lista = new List<ItemTarefa>();
TarefaBL tbl = new TarefaBL();
lista = tbl.buscaItensTarefa(idTarefa);
DataColumn c1 = new DataColumn("data", Type.GetType("System.String"));
DataColumn c2 = new DataColumn("descricao", Type.GetType("System.String"));
DataColumn c3 = new DataColumn("excluir", Type.GetType("System.String"));
dt.Columns.Add(c1);
dt.Columns.Add(c2);
dt.Columns.Add(c3);
foreach (ItemTarefa t in lista)
{
EtapaBL ebl = new EtapaBL();
DataRow dr = dt.NewRow();
dr["data"] = t.data.ToString();
dr["descricao"] = t.descricao.ToString();
dr["excluir"] = "ExcluirItemTarefa.aspx?id_item=" + t.id.ToString();
dt.Rows.Add(dr);
}
gridItens.DataSource = dt.Copy();
gridItens.DataBind();
}
示例14: QUERY_CRM041_MAIN_AND_DETL
/// <summary>
/// 取得 VDS_CRM_ORDER_MAIN && VDS_CRM_ORDER_DETL 的 Data
/// </summary>
/// <param name="ParameterList"></param>
/// <returns>回傳查詢結果</returns>
public DataSet QUERY_CRM041_MAIN_AND_DETL(ArrayList ParameterList)
{
try
{
DataSet ds_Return = new DataSet();
DataTable dt_Return_Main = new DataTable();
DataTable dt_Return_Detl = new DataTable();
DBO.VDS_CRM_ORDER_MAINDBO VCOM = new VDS_CRM_ORDER_MAINDBO(ref USEDB);
DBO.VDS_CRM_ORDER_DETLDBO VCOD = new VDS_CRM_ORDER_DETLDBO(ref USEDB);
dt_Return_Main = VCOM.QUERY_CRM041_MAIN(ParameterList);
dt_Return_Main.TableName = "VDS_CRM_ORDER_MAIN";
dt_Return_Detl = VCOD.QUERY_CRM041_DETL(ParameterList);
dt_Return_Detl.TableName = "VDS_CRM_ORDER_DETL";
ds_Return.Tables.Add(dt_Return_Main.Copy());
ds_Return.Tables.Add(dt_Return_Detl.Copy());
dt_Return_Main.Clear();
dt_Return_Detl.Clear();
dt_Return_Main.Dispose();
dt_Return_Detl.Dispose();
return ds_Return;
}
catch (Exception ex)
{ throw GetNewException(ex); }
}
示例15: ConvertEMeterTransaction
public DataTable ConvertEMeterTransaction(DataTable _dt, int adcID)
{
DataTable dt = _dt.Copy();
//
string sID = "device_adc_id";
string sDate = "e_datetime";
//
if (!dt.Columns.Contains(sID))
dt.Columns.Add(new DataColumn(sID, typeof(int), "'" + adcID + "'"));
//
if (!dt.Columns.Contains(sDate))
dt.Columns.Add(new DataColumn(sDate, typeof(DateTime),
"Convert(E_Date + ' ' + E_Time, 'System.DateTime')"));
//
string sConnection = "e_connection";
if (!dt.Columns.Contains(sConnection))
dt.Columns.Add(new DataColumn(sConnection, typeof(int),
"Convert(IIF(E_CommStatus like '%complete',1,0), 'System.Int16')"));
//
foreach (DataRow r in dt.Rows)
{
foreach(DataColumn c in dt.Columns)
if(r[c.ColumnName].ToString().Contains("null"))
r[c.ColumnName] = "0";
}
dt.AcceptChanges();
//
return dt;
}