有人可以帮我使用 WebMatrix 2 逐行打印数据吗
我正在尝试使用 excel 2007 和/或 2003 最后一行 DataGrid1 不起作用。这是我尝试的第三天,请帮助。
String Excel = "C://TEST/test_2.xls";
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Excel +";Extended Properties=Excel 8.0;";
string.System.Data.OleDb.OleDbConnection objConn = new`system.Data.OleDb.OleDbConnection(sConnectionString);`
objConn.Open();
System.Data.OleDb.OleDbCommand objCmdSelect = new System.Data.OleDb.OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
System.Data.OleDb.OleDbDataAdapter objAdapter1 = new System.Data.OleDb.OleDbDataAdapter(objCmdSelect);
System.Data.DataSet objDataset1 = new System.Data.DataSet();
objAdapter1.Fill(objDataset1, "XLData");
objConn.Close();
int c = objDataset1.Tables[0].Columns.Count;
int count =0;
//For Test
Response.Write("Colums: "+objDataset1.Tables[0].Columns.Count.ToString()+"<br>");
Response.Write("Rows: "+objDataset1.Tables[0].Rows.Count.ToString()+"<br>");
// Bind data to DataGrid control. Following part not working, also i like to print data with for or foreach loop)
DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();
//Other option if Data.Grid does not work!!
change Rows to Columns to print Columns.
for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
Response.Write(objDataset1.Tables[0].Rows[i].ItemArray[j]+" ");
}
Response.Write("<br>");
}