![](/img/trans.png)
[英]How can i skip extra rows in excel while importing it into database using SqlBulkCopy?
[英]How can i add a extra column while importing excel into database?
我正在將excelsheet導入sql服務器數據庫中,在excel中有一個名為FlightNumber的列,其格式為AI-2000,AI-2564等,我在數據庫中有FlightNumber列,但還有另一個名為FlightId的列,該列應具有從excel的值派生的值flightnumber(通過刪除前3個字符)例如:如果excel中有FlightNumber:AI-2032,則db中的FlightId值應為2032。我應該怎么做? 我是一個初學者,所以您可能需要解釋一些代碼。
這就是我閱讀excel的方式:
DataTable dt7 = new DataTable();
dt7.Load(dr);
DataRow[] ExcelRows = new DataRow[dt7.Rows.Count];
DataColumn[] ExcelColumn = new DataColumn[dt7.Columns.Count];
DataRow[] ExcelRows = new DataRow[dt7.Rows.Count];
//=================================================
for (int i1 = 0; i1 < dt7.Rows.Count; i1++)
{
if (dt7.Rows[i1]["PP NO"] == null)
dt7.Rows[i1]["PP NO"] = 0;
}
我也正在使用SqlBulkCopy與列映射一起導入
嘗試這個
DataTable dtone = new DataTable();
dtone.Columns.Add("idNumber");
dtone.Columns.Add("idOnly", typeof(string), " substring(idNumber, 4, 100)");
dtone.Rows.Add("AI-2000");
dtone.Rows.Add("AE-2001");
dtone.Rows.Add("AF-2002");
dtone.Rows.Add("AH-2003");
這里的第三個參數是DataColumn.Expression
,它根據您現有的列值指定默認值,以在此處了解有關此訪問的更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.