Pass OleDbParameter to OleDbCommand (VB.net) : OleDBCommand « 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 GetData(Sender as Object, e as EventArgs) 
      dim objCmd as OleDbCommand = new OleDbCommand _
         ("select * from employee where ID = @ID", Conn)
      dim objReader as OleDbDataReader
      
      dim objParam as OleDbParameter
      objParam = objCmd.Parameters.Add("@ID", OleDbType.Integer)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbID.Text
           
      try
         objCmd.Connection.Open()
         objReader = objCmd.ExecuteReader
      catch ex as OleDbException
         Label1.Text = "Error retrieving from the database."
      end try
       
      DataGrid1.DataSource = objReader
      DataGrid1.DataBind()
       
      objReader.Close
      objCmd.Connection.Close()
   end sub
</script>

<html><body>
   <form runat="server">
      <asp:Label id="Label1" runat="server"
         maintainstate=false /><br>
      Enter an ID: <asp:TextBox id="tbID" runat="server"
         AutoPostBack=True
         OnTextChanged=GetData />
      <asp:DataGrid id="DataGrid1" runat="server" 
         BorderColor="black" 
         width="100%"
         AutoGenerateColumns="true" />
   </form>
</body></html>








18.12.OleDBCommand
18.12.1.Use OleDBCommand to read data returned from a select statement (C#)
18.12.2.Pass OleDbParameter to OleDbCommand (VB.net)
18.12.3.Call stored procedure and pass in parameters (VB.net)
18.12.4.Execcute delete statement
18.12.5.Create OleDbDataReader object from OleDbCommand