绑定数据到DataGrid private void Bind() ...{ try ...{ string strSql="select * from house"; SqlDataAdapter da=new SqlDataAdapter(strSql,conn); DataSet ds=new DataSet(); da.Fill(ds,"TableName"); this.dgRole.DataSource=ds; this.dgRole.DataBind(); } catch(Exception Err) ...{ Response.Write(Err.Message); } } 通过按钮事件将数据插入EXCEL OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ this.MapPath("/Project/UserUpload/Role.xls")+";Extended Properties=Excel 8.0;"); OleDbCommand cmd = cn.CreateCommand(); cmd.CommandText = "CREATE TABLE Role (列名1 VARCHAR(10),列名2 VARCHAR(20))"; cn.Open(); cmd.ExecuteNonQuery(); for(int i=0;i<this.dgRole.Items.Count;i++) ...{ cmd.CommandText = "INSERT INTO [Role$] VALUES('"+ this.dgRole.Items[i].Cells[0].Text+"','"+ this.dgRole.Items[i].Cells[1].Text+"')"; cmd.ExecuteNonQuery(); } cn.Close();