我读取excel表时出现了个奇怪的问题
有一个编号列,如果第一行是数字,那么之后有字母的化返回dbNull,
例
编号
1234
12jad
那么第一次能读出 1234,第2次是dbNull! ,哭了,问什么?
程序如下
public int ReadItemData(string path)
{
string strSel = "SELECT * FROM [数据接口$]";
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +path + ";Extended Properties=\"Excel 8.0;\"";
OleDbConnection conn = new OleDbConnection(strConn);
if(conn.State!=ConnectionState.Open)
conn.Open();
OleDbCommand cmd=new OleDbCommand(strSel,conn);
OleDbDataReader reader=cmd.ExecuteReade(CommandBehavior.CloseConnection);
while(reader.Read())
{
table.Rows.Add(new object[] {reader["编号"]});
}
return length;
}
是excel的问题吗?还是什么问题?
求助啊,最好说具体点
有一个编号列,如果第一行是数字,那么之后有字母的化返回dbNull,
例
编号
1234
12jad
那么第一次能读出 1234,第2次是dbNull! ,哭了,问什么?
程序如下
public int ReadItemData(string path)
{
string strSel = "SELECT * FROM [数据接口$]";
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +path + ";Extended Properties=\"Excel 8.0;\"";
OleDbConnection conn = new OleDbConnection(strConn);
if(conn.State!=ConnectionState.Open)
conn.Open();
OleDbCommand cmd=new OleDbCommand(strSel,conn);
OleDbDataReader reader=cmd.ExecuteReade(CommandBehavior.CloseConnection);
while(reader.Read())
{
table.Rows.Add(new object[] {reader["编号"]});
}
return length;
}
是excel的问题吗?还是什么问题?
求助啊,最好说具体点
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货