我有一个Excel工作表我想读入数据表 - 除了Excel表格中的一个特定列之外,一切都很好.列,"产品ID",就像是值的组合##########和n#########.
我试图让OleDB通过将其读入数据集/数据表来自动处理所有内容,但"ProductID"中的任何值都会n######丢失,忽略并留空.我尝试通过使用datareader循环遍历每一行来手动创建我的DataTable,但结果完全相同.
这是代码:
// add the column names manually to the datatable as column_1, column_2, ...
for (colnum = 0; colnum < num_columns; colnum ++){
ds.Tables["products"].Columns.Add("column_" +colnum , System.Type.GetType("System.String"));
}
while(myDataReader.Read()){
// loop through each excel row adding a new respective datarow to my datatable
DataRow a_row = ds.Tables["products"].NewRow();
for (col = 0; col < num_columns; col ++){
try { a_row[col] = rdr.GetString(col); }
catch { a_row[col] = …Run Code Online (Sandbox Code Playgroud)