CSharp Get Command From Oledbcommandbuilder – 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 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.CommandText
    lblUpdateCommand.Text = objAdapter.UpdateCommand.CommandText
    lblInsertCommand.Text = objAdapter.InsertCommand.CommandText
    lblDeleteCommand.Text = objAdapter.DeleteCommand.CommandText  End Sub</script><html>
  <table border="1">
    <td><asp:Label id="lblSelectCommand" runat="server" />
    <td><asp:Label id="lblUpdateCommand" runat="server" />
    <td>InsertCommand </td>
    <td><asp:Label id="lblInsertCommand" runat="server" />
    <td><asp:Label id="lblDeleteCommand" runat="server" />

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.