<html>
<script runat="server">
dim MyConnection as OleDbConnection
dim cmdSelect as OleDbCommand
dim dtrReader as OleDbDataReader
Sub Page_Load(sender As Object, e As EventArgs)
MyConnection = New OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/db/kk.mdb")
If Not IsPostBack Then
BindGrid()
End If
End Sub
Sub BindGrid()
Dim MyCommand As OleDbDataAdapter = new OleDbDataAdapter("select * from [board]", MyConnection)
Dim DS As DataSet = new DataSet()
MyCommand.Fill(DS,"min")
MyDataGrid.DataSource =DS.Tables("min").DefaultView
MyDataGrid.DataBind()
End Sub
Sub Mydatagrid_PageIndexChanged(s as object,e as DataGridPageChangedEventargs)
MyDataGrid.CurrentPageIndex=e.newPageIndex
BindGrid()
End Sub
Sub Button1_Click(sender As Object, e As System.EventArgs)
'-------------------
MyDataGrid.AllowPaging = "false"
BindGrid()
'-------------------
MyDataGrid.SelectedItemStyle.BackColor=Color.white
MyDataGrid.AlternatingItemStyle.BackColor=Color.white
MyDataGrid.ItemStyle.BackColor=Color.white
MyDataGrid.HeaderStyle.BackColor=Color.white
MyDataGrid.HeaderStyle.ForeColor=Color.red
'----------
dim resp as HttpResponse = Page.Response
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
MyDataGrid.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
'-------------------
MyDataGrid.AllowPaging = "true"
BindGrid()
End Sub
理解错了,我用的是下面的代码
int rowIndex=1;
string User_ID="3";
Sql.TSqlDB db=new Sql.TSqlDB();
string strSel="select * from tb_sjsj where User_ID='"+User_ID+"' order by id asc";
SqlDataAdapter sqldata=new SqlDataAdapter(strSel,db.SqlConn);
DataSet myset=new DataSet();
sqldata.Fill(myset,"tb_sjsj");
db.SqlConn.Close();
Excel.Application app = new Excel.ApplicationClass();