Using Stored Procedures With Parameters: filter : Stored Procedure Parameters « ADO.net Database « ASP.Net






Using Stored Procedures With Parameters: filter

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
  <head><title>Using Stored Procedures With Parameters</title></head>
  <body>
    <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" />
      <br/><br/>
      <asp:DataGrid id="dgOutput" runat="server" />
    </form>
  </body>
</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)
  objCommand.Parameters.Add(objParameter)
  objParameter.Direction = ParameterDirection.Input
  objParameter.Value = txtRegion.Text

  objConnection.Open()

  dgOutput.DataSource = objCommand.ExecuteReader()
  dgOutput.DataBind()

  objConnection.Close()
End Sub
</script>
           
       








Related examples in the same category

1.Using Stored Procedures With Output Parameters
2.Using a Built-in Stored Procedure With Parameters