Call stored procedure to query data table (VB.net) : Stored procedure « ADO.net Database « ASP.NET Tutorial






<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">
   'declare connection
   dim Conn as new OleDbConnection( _
            "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
            & "DATA SOURCE=" _
            & Server.MapPath("EmployeeDatabase.mdb;"))

   sub Submit(Sender as Object, e as EventArgs)
      dim objCmd as OleDbCommand = new OleDbCommand("SelectIDFromName", Conn)
      dim objReader as OleDbDataReader
      objCmd.CommandType = CommandType.StoredProcedure

      dim objParam as OleDbParameter
      objParam = objCmd.Parameters.Add("@FirstName", OleDbType.Char)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbFirst.Text

      objParam = objCmd.Parameters.Add("@LastName",OleDbType.Char)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbLast.Text

      try
         objCmd.Connection.Open()
         objReader = objCmd.ExecuteReader
      catch ex as OleDbException
         Response.Write("Error retrieving data.")
      end try

      DataGrid1.DataSource = objReader
      DataGrid1.DataBind()

      objCmd.Connection.Close()
   End Sub
   
</script>

<html><body>
   <form runat="server">
      Enter a first name:
      <asp:TextBox id="tbFirst" runat="server"/><br>
      Enter a last name:
      <asp:TextBox id="tbLast" runat="server"/>

      <asp:Button id="btSubmit" runat="server"
         Text="Submit"
         OnClick="Submit"/>

      <asp:DataGrid id="DataGrid1" runat="server" 
         AutoGenerateColumns="true" />
   </form>
</body></html>








18.55.Stored procedure
18.55.1.Call stored procedure to query data table (VB.net)
18.55.2.Use SQL Server stored procedures to insert a new record and then retrieve the identity value
18.55.3.Handling Return Parameters from a Stored Procedure
18.55.4.Handling Output Parameters from a Stored Procedure