0
我正在創建windows應用程序,以便將Excel文件中的數據插入到數據庫中。我的應用程序工作正常,但在將excel文件中的數據顯示到數據網格視圖並插入數據庫之後,它會插入一個空行。從Excel文件中讀取數據
這裏是我的代碼,
//we need to copy the data from datagridview into data table
DataTable dtable = new DataTable();
dtable.TableName = "PRODUCTS";
//we need to copy column from datagridview into data table
foreach (DataGridViewColumn col in ExcelDataGV.Columns)
{
dtable.Columns.Add(col.DataPropertyName, col.ValueType);
}
//we need to copy rows from datagridview into data table
foreach (DataGridViewRow row in ExcelDataGV.Rows)
{
if (row.IsNewRow)
continue;
DataRow dtRow = dtable.NewRow();
for (int i = 0; i < ExcelDataGV.Columns.Count; i++)
dtRow[i] = (row.Cells[i].Value == null ? DBNull.Value : row.Cells[i].Value);
dtable.Rows.Add(dtRow);
}
//foreach loop will read data from data table and insert/add those value in database
foreach (DataRow dr in dtable.Rows)
{
}
我需要修改我的循環語句?
您顯示的代碼不會被編譯。一個'foreach'循環通常包含一個body。你介意顯示它?事實上,在這個問題關閉之前,你介意顯示一些實際的代碼? – 2011-05-02 20:12:28
@Darin:我編輯了我的問題。 – user735052 2011-05-02 20:15:28