CSharp Call Store Procedure (Vb.Net) – ADO.Net Database

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %><script language="VB" runat="server">  Sub Page_Load(Sender As Object, E As EventArgs)    Dim objConnection As OleDbConnection
    Dim objCmd        As OleDbCommand
    Dim strConnection As String
 
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source=C:\Northwind.mdb"
    ' Create and open the connection object
    objConnection = New OleDbConnection(strConnection)
    objConnection.Open()
 
    ' Create the Command and set its properties
    objCmd = New OleDbCommand()
    objCmd.Connection = objConnection
    objCmd.CommandText = "[Sales by Category]"
    objCmd.CommandType = CommandType.StoredProcedure    dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
    dgSales.DataBind()  End Sub</script><html>
  <body>
    <h2>Using a stored procedure</h2>
    <asp:datagrid id="dgSales" runat="server" />
  </body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.