直接100分,一个从dataset中取数据的小问题,本人使用c#两天,还请大家帮忙
EXCEL中的数据,这是第一列,后面的省略
室号
401A
402B
403
404
405A
406B
string connect = @"Provider=Microsoft.JET.OLEDB.4.0; data source=E:\sandbox\dotnet\database\new.xls;Extended Properties=Excel 8.0;";
string sql = "select * from [统计$]";
OleDbConnection db_conn = new OleDbConnection(connect);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(sql, db_conn);
foreach (DataRow row in dt.Rows)
{
string s = (string)row["室号"];
MessageBox.Show(s);
}
db_conn.Close();
开始两个都正常,到第三个竟然报Unable to cast object of type 'System.DBNull' to type 'System.String'
接受不了
唯一的区别就是开头两个带字母,第三个是数字,但我已经在excel中将格子的属性改为文本了
而且dt.Columns["室号"].DataType也是String
这不是折腾嘛
大家帮忙,感谢万分