Create an aspx page with a DataGrid named DG. Then the following code will
populate it from an Access database with DSN named MyDSN. The datagrid is
also sortable.
Public Class ODBCTest
Inherits System.Web.UI.P age
Protected DC As New Data.Odbc.OdbcC onnection
Protected DA As New Data.Odbc.OdbcD ataAdapter
Protected WithEvents DG As System.Web.UI.W ebControls.Data Grid
Protected DS As New Data.DataSet
Protected DataGrid_Sort As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
DataGrid_Sort = "ID"
Bind_Grid(DataG rid_Sort)
Else
Bind_Grid(DataG rid_Sort)
End If
End Sub
Private Sub Bind_Grid(ByVal sorting As String)
If DC.State = ConnectionState .Open Then DC.Close()
DS.Clear()
DC.ConnectionSt ring = "MaxBufferSize= 2048;FIL=MS
Access;DSN=MyDS N;PageTimeout=5 "
DC.Open()
DA.SelectComman d = New Data.Odbc.OdbcC ommand("select * from [main]",
DC)
DA.Fill(DS)
Dim DV As New Data.DataView(D S.Tables(0))
DV.Sort = sorting
DG.DataSource = DV
DG.Visible = True
DG.AllowSorting = True
DG.DataBind()
End Sub
"HB" <hb******@proma star.com> wrote in message
news:uK******** ******@tk2msftn gp13.phx.gbl...
Guys,
How to use ODBC with a DB connection in ASP.NET?
each time I try to add the ODBC name in the connection an error telling
that it is not compatible (or so) to use ODBC.
I have .NET 2002 with ver. 1 framework.
Thanks
HB