Bind asp:DataGrid to access database (VB.net) : DataGrid « ADO.net Database « ASP.Net






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

1.Pagable datagrid (VB.net)
2.Bind data through SqlConnection to asp:DataGrid (VB.net)
3.Bind to two different asp:datagrid (VB.net)
4.asp:datagrid: sort expression (VB.net)
5.Sort asp:datagrid (VB.net)
6.Bind Data to asp DataGrid in C#
7.Set asp:datagrid title bar (C#)