Viewing source for recipe1012vb.aspx
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
End Sub
Sub GetRecords_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source="& Server.MapPath("Northwind.mdb") & ";"
' TODO: Updatd the name of the Stored Procedure for your application
Dim CommandText As String = "[Sales By Year]"
Dim _Connection As New OleDbConnection(ConnectionString)
Dim _Command As New OleDbCommand(CommandText, _Connection)
Dim _BeginingDate As New OleDbParameter()
Dim _EndingDate As New OleDbParameter()
_Command.CommandType = CommandType.StoredProcedure
' TODO: Set the input parameter, if necessary, for your application
_Command.Parameters.Add("@BeginningDate", DbType.Date).Value = BeginingDateTextBox.Text
_Command.Parameters.Add("@EndingDate", DbType.Date).Value = EndingDateTextBox.Text
Try
_Connection.Open()
DataGrid1.DataSource = _Command.ExecuteReader(CommandBehavior.CloseConnection)
DataGrid1.DataBind()
Catch Err As Exception
ErrLiteralControl.Text = Err.ToString()
Finally
_Connection.Close()
End Try
End Sub
</script>
<html>
<head>
<title>Invoking Parameterized Query Objects in Microsoft Access</title>
</head>
<body style="FONT-FAMILY: arial">
<form runat="server">
<h2>Parameterized Query Objects in Microsoft Access
<hr size="1" />
</h2>
<p>
Beginning Date<asp:TextBox id="BeginingDateTextBox" runat="server"></asp:TextBox>
Ending Date<asp:TextBox id="EndingDateTextBox" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="GetRecords" onclick="GetRecords_Click" runat="server" Text="Get Records"></asp:Button>
</p>
<p>
<asp:datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False">
<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</p>
<p>
<asp:Literal id="ErrLiteralControl" runat="server" EnableViewState="False"></asp:Literal>
</p>
</form>
</body>
</html>