Bind asp:DataGrid to access database (VB.net)
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script language="vb" runat="server">
Sub Page_Load()
Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=yourDatabase.mdb"
data_src.text = strConnection
Dim strSQL as string = "SELECT * FROM products;"
Dim objDataSet as new DataSet()
Dim objConnection as new OledbConnection(strConnection)
Dim objAdapter as new OledbDataAdapter(strSQL, objConnection)
objAdapter.Fill(objDataSet, "products")
Dim objDataView as New DataView(objDataSet.Tables("products"))
dgNameList.DataSource=objDataView
dgNameList.DataBind()
end Sub
</script>
<html>
<body>
<h4>Reading data from the connection
<asp:label id="data_src" runat="server"/> to the DataGrid control.</h4>
<asp:datagrid id="dgNameList" runat="server" /><br />
</body>
</html>
Related examples in the same category