CSharp Using Stored Procedures With Parameters: Filter – ADO.Net Database

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %><html>
  <head><title>Using Stored Procedures With Parameters</title></head>
    <form runat="server" method="post">
      Enter a State Code:
      <asp:Textbox id="txtRegion" runat="server" />
      <asp:Button id="btnSubmit" runat="server"
                  Text="Search" OnClick="Submit" />
      <asp:DataGrid id="dgOutput" runat="server" />
</html><script language="VB" runat="server">
Sub Submit(ByVal Source As Object, ByVal E As EventArgs)  Dim strConnection As String = ConfigurationSettings.AppSettings("NWind")
  Dim objConnection As New SqlConnection(strConnection)
  Dim objCommand As New SqlCommand("sp_CustomersByState", objConnection)
  objCommand.CommandType = CommandType.StoredProcedure  Dim objParameter As New SqlParameter("@region", SqlDbType.NVarChar, 15)
  objParameter.Direction = ParameterDirection.Input
  objParameter.Value = txtRegion.Text  objConnection.Open()  dgOutput.DataSource = objCommand.ExecuteReader()
  dgOutput.DataBind()  objConnection.Close()
End Sub

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.