CSharp Display Column Alias In Asp Datagrid – ADO.Net Database

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim DBConn as OleDbConnection
    Dim DBCommand As OleDbDataAdapter
    Dim DSPageData as New DataSet
    DBConn = New OleDbConnection( _
        "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
        & "DATA SOURCE=" _
        & Server.MapPath _
        ("ProductsDB.mdb;"))
    DBCommand = New OleDbDataAdapter _
        ("Select ProductName as [Name], " _
        & "ProductDescription as [Description], Price " _
        & "From Products Where " _
        & "Datediff(""d"",DateAdded,Now) <= 31 " _
        & "Order by ProductName", DBConn)
    DBCommand.Fill(DSPageData, _
        "NewProducts")
    dgNewProducts.DataSource = _
        DSPageData.Tables("NewProducts").DefaultView
    dgNewProducts.DataBind()
End Sub
</script>
<html>
<head>
<title>New Products</title>
</head>
<body LEFTMARGIN="40">
<form runat="server">
<br /><br />
<asp:label
    id="lblMessage1"
    font-size="12pt"
    font-bold="True"
    font-name="Lucida Console"
    text="New Products added during the past month!"
    runat="server"
/>
<br /><br />
<asp:datagrid
    id="dgNewProducts"
    runat="server"
    autogeneratecolumns="True"
/>
</form>
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.