ASP.Net/ADO.net Database/OleDbCommandBuilder
Get command from OleDbCommandBuilder
<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 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>
Command | CommandText |
SelectCommand | <asp:Label id="lblSelectCommand" runat="server" /> |
UpdateCommand | <asp:Label id="lblUpdateCommand" runat="server" /> |
InsertCommand | <asp:Label id="lblInsertCommand" runat="server" /> |
DeleteCommand | <asp:Label id="lblDeleteCommand" runat="server" /> |
</body>
</html>
</source>