ASP.Net/ADO.net Database/Store Procedure OleDbConnection
Содержание
Call stored procedure in access database (VB.net)
<%@ 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>
<h2>Using a stored procedure</h2>
<asp:datagrid id="dgSales" runat="server" />
</body>
</html>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure through OldDbconnection in C#
<%@ 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>
<h2>Using a stored procedure</h2>
<asp:datagrid id="dgSales" runat="server" />
</body>
</html>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure through OleDbConnection (VB.net)
<%@ 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>
<h2>Using a stored procedure</h2>
<asp:datagrid id="dgSales" runat="server" />
</body>
</html>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>
Call store procedure (VB.net)
<%@ 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>
<h2>Using a stored procedure</h2>
<asp:datagrid id="dgSales" runat="server" />
</body>
</html>