ASP.Net/ADO.net Database/Store Procedure OleDbConnection
Содержание
- 1 Call stored procedure in access database (VB.net)
- 2 Using a stored procedure
- 3 Call store procedure through OldDbconnection in C#
- 4 Using a stored procedure
- 5 Call store procedure through OleDbConnection (VB.net)
- 6 Using a stored procedure
- 7 Call store procedure (VB.net)
- 8 Using a stored procedure
Call stored procedure in access database (VB.net)
<source lang="csharp">
<%@ 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" objConnection = New OleDbConnection(strConnection) objConnection.Open() objCmd = New OleDbCommand() objCmd.Connection = objConnection objCmd.rumandText = "[Sales by Category]" objCmd.rumandType = CommandType.StoredProcedure dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection) dgSales.DataBind() End Sub
</script> <html>
<body>
Using a stored procedure
<asp:datagrid id="dgSales" runat="server" /> </body>
</html>
</source>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure through OldDbconnection in C#
<source lang="csharp">
<%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script Language="c#" runat="server">
void Page_Load(object sender, EventArgs e) { OleDbConnection objConnection = null; OleDbCommand objCmd = null; string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;"; strConnection += @"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.rumandText = "[Sales by Category]"; objCmd.rumandType = CommandType.StoredProcedure; dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection); dgSales.DataBind(); }
</script> <html>
<body>
Using a stored procedure
<asp:datagrid id="dgSales" runat="server" /> </body>
</html>
</source>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure through OleDbConnection (VB.net)
<source lang="csharp">
<%@ 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.rumandText = "[Sales by Category]" objCmd.rumandType = CommandType.StoredProcedure dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection) dgSales.DataBind() End Sub
</script> <html>
<body>
Using a stored procedure
<asp:datagrid id="dgSales" runat="server" /> </body>
</html>
</source>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure (VB.net)
<source lang="csharp">
<%@ 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.rumandText = "[Sales by Category]" objCmd.rumandType = CommandType.StoredProcedure dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection) dgSales.DataBind() End Sub
</script> <html>
<body>
Using a stored procedure
<asp:datagrid id="dgSales" runat="server" /> </body>
</html>
</source>