Casting error when setting source with axSpreadsheet control
I use the axSpreadsheet control开发者_如何学Python in C#, but when I set the source there's an error.
error: can not cast "System.Data.DataTable" to "msdatasrc.DataSource"
My Code:
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filename + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [电子订单$]", conn);
odda.Fill(ds, "table");
axSpreadsheet1.DataSource = ds.Tables[0];
Then I modify the code: axSpreadsheet1.DataSource = ds.Tables[0];
to axSpreadsheet1.DataSource = (msdatasrc.DataSource)ds.Tables[0];
, and still have the error.
What can I do?
One obvious solution is to examine what is msdatasrc.DataSource
. Create a new instance of it and than copy over the table rows to it, row by row or by using some other tool.
精彩评论