ASP.Net/ADO.net Database/OleDbCommandBuilder

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Get command from OleDbCommandBuilder

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
  Sub Page_Load(Sender As Object, E As EventArgs)
    Dim strConnection As String
    Dim strSQL        As String
    Dim objDataSet    As New DataSet()
    Dim objConnection As OleDbConnection
    Dim objAdapter    As OleDbDataAdapter
    Dim objCommand    As OleDbCommand
    Dim objBuilder    As OleDbCommandBuilder
    " set the connection and query details
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
                    "Data Source=c:\Northwind.mdb"
    strSQL = "SELECT EmployeeID, FirstName, LastName FROM Employees"
    " open the connection and set the command
    objConnection = New OledbConnection(strConnection)
    objAdapter = New OledbDataAdapter(strSQL, objConnection)
    " create the other commands
    objBuilder = New OleDbCommandBuilder(objAdapter)
    objAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
    objAdapter.InsertCommand = objBuilder.GetInsertCommand()
    objAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
    
    " now display the CommandText property from each command
    lblSelectCommand.Text = objAdapter.SelectCommand.rumandText
    lblUpdateCommand.Text = objAdapter.UpdateCommand.rumandText
    lblInsertCommand.Text = objAdapter.InsertCommand.rumandText
    lblDeleteCommand.Text = objAdapter.DeleteCommand.rumandText
  End Sub
</script>
<html>
 <body>
  <table border="1">
   <tr>
    <td>Command</td>
    <td>CommandText</td>
   </tr>
   <tr>
    <td>SelectCommand</td>
    <td><asp:Label id="lblSelectCommand" runat="server" />
   </tr>
   <tr>
    <td>UpdateCommand</td>
    <td><asp:Label id="lblUpdateCommand" runat="server" />
   </tr>
   <tr>
    <td>InsertCommand </td>
    <td><asp:Label id="lblInsertCommand" runat="server" />
   </tr>
   <tr>
    <td>DeleteCommand</td>
    <td><asp:Label id="lblDeleteCommand" runat="server" />
   </tr>
  </table>
 </body>
</html>