Public Class ExcelExport Inherits System.Web.UI.Page Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid #Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub
#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load '在此处放置初始化页的用户代码 ' 定义是否是 SQL Server 数据库,这里为False Dim blnIsSQLServer As System.Boolean = False Dim strSQL As String Dim objDataset As New DataSet() Dim objConn As Object Dim strCnn As String If blnIsSQLServer Then strCnn = "User ID=sa;Initial Catalog=Northwind;Data Source=.\NetSDK;" objConn = New System.Data.SqlClient.SqlConnection(strCnn) objConn.Open() Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter() strSQL = "Select * from customers where country='USA'" objAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL, objConn) objAdapter.Fill(obj