如何在不丢失ASP.NET C中的数据的情况下删除数据表的列标题# [英] How to remove column header of a data table without losing data in ASP.NET C#
本文介绍了如何在不丢失ASP.NET C中的数据的情况下删除数据表的列标题#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不丢失asp.net c#中的数据的情况下删除数据表的列标题?
我从excel通过Oledb获取数据到数据表而我正在将它输出到另一个。我想删除数据表的列标题而不会丢失列值。
我尝试过:
How to remove column header of a data table without losing data in asp.net c# ?
I am fetching the data from excel via Oledb to a data table and I am exporting the same to another. I want to remove the column header of the data table without losing column value.
What I have tried:
string filelocation1 = @"D:\Alex\Arab_Test_1.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filelocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
//create connection
OleDbConnection oleDBConnection = new OleDbConnection(connectionString);
oleDBConnection.Open();
//create the adapter with the select to get
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [Sheet1$]", oleDBConnection);
// Create the dataset and fill it by using the adapter.
DataTable dataTable = new DataTable();
adapter.FillSchema(dataTable, SchemaType.Source);
adapter.Fill(dataTable);
DataSet ds=new DataSet();
ds.Tables.Add(dataTable);
for (int rowNo = 0; rowNo < ds.Tables[0].Rows.Count; rowNo++)
{
for (int colNo = 0; colNo < ds.Tables[0].Columns.Count; colNo++)
{
newCERecord[rowNo] = ds.Tables[0].Rows[rowNo][colNo].ToString();
}
//iRow++;
}
// Call update on the adapter to save all the changes to the dataset
adapter.Update(dataTable);
推荐答案
,oleDBConnection);
// 创建数据集并使用适配器填充它。
DataTable dataTable = new DataTable();
adapter.FillSchema(dataTable,SchemaType.Source);
adapter.Fill(dataTable);
DataSet ds = new DataSet();
ds.Tables.Add(dataTable);
for ( int rowNo = 0 ; rowNo < ds.Tables [ 0 ]。Rows.Count; rowNo ++)
{
for ( int colNo = 0 ; colNo < ds.Tables [ 0 ]。列。 Count; colNo ++)
{
newCERecord [rowNo] = ds.Tables [ 0 ]。行[rowNo] [colNo] .ToString() ;
}
// iRow ++;
}
// 调用适配器上的更新以保存所有更改数据集
adapter.Update(dataTable);
", oleDBConnection); // Create the dataset and fill it by using the adapter. DataTable dataTable = new DataTable(); adapter.FillSchema(dataTable, SchemaType.Source); adapter.Fill(dataTable); DataSet ds=new DataSet(); ds.Tables.Add(dataTable); for (int rowNo = 0; rowNo < ds.Tables[0].Rows.Count; rowNo++) { for (int colNo = 0; colNo < ds.Tables[0].Columns.Count; colNo++) { newCERecord[rowNo] = ds.Tables[0].Rows[rowNo][colNo].ToString(); } //iRow++; } // Call update on the adapter to save all the changes to the dataset adapter.Update(dataTable);
在连接字符串集中HDR =否。
问候。
In the connection string set HDR=No.
Regards.
这篇关于如何在不丢失ASP.NET C中的数据的情况下删除数据表的列标题#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文