Browsing and Manipulating Data with a Form

This section presents a sample that demonstrates how to manage browsing, inserts, deletes, and updates through a Windows form. You have already seen bits and pieces of this code, but no prior sample brought all the elements together in one simple application. You can use this sample as is or as a starting point for more highly customized applications. The sample s presentation starts with the form design and operation. Then, the discussion of the sample moves to the form load event procedure, which prepares for the browsing and data manipulation functions. The focus then shifts to procedures managing browsing, inserts , deletes, and updates.

The sample works with a version of the Shippers table in the Northwind database. Because this sample explicitly enables data manipulation, the sample application actually works with a copy of the Shippers table named VBDotNetShippers. This approach enables you to restore the table at any time by simply deleting the current version of the VBDotNetShippers table and making a new copy of the original Shippers table in the Northwind database. You can create the VBDotNetShippers table from the Database window in the Northwind database with the following steps:

  1. Select the Shippers table and choose Edit, Copy.

  2. Next , choose Edit, Paste.

  3. Click the Structure And Data radio button if it is not already selected in the Paste Table As dialog box. Type VBDotNetShippers in the Table Name box.

  4. Click OK.

    Note  

    Although the application works with the VBDotNetShippers table in the Northwind database, the local DataTable object coordinated with the VBDotNetShippers table has the name Shippers. This makes for less typing. The distinction also helps to clarify when the discussion refers to an Access database table and when it refers to a local DataTable object in a dataset.

Design and Operational Views of Form3

Figure 9-13 presents design and operational views of Form3 in the DatasetForms project. Three text boxes enable the viewing of column values, and two of those text boxes permit the editing of the values that appear within them. The text box for the ShipperID column values has its ReadOnly property set to True; this permits viewing but not editing of the text box s contents. Because ShipperID is an autonumber field, the Access database manages its value. Users can view and modify the contents of the other two text boxes.

click to expand
Figure 9-13: Design and operational views of a Windows form for data browsing and manipulation

The form offers four buttons for browsing that appear above four more buttons for data manipulation. The browsing buttons from left to right enable moves to the first, previous, next, and last row in the DataTable object ( Shippers ) serving as the source for the form. The button Name properties are Button1 through Button4 from left to right.

A pair of buttons directly below the browsing buttons enables inserts. By clicking Button5 , a user clears the form and disables the connection between the form s text boxes and the Shippers DataTable to permit the input of column values for a new row. After data entry is complete, a click of Button6 launches an update of the VBDotNetShippers table in the Northwind database and the matching DataTable object in the local dataset. The application updates the Northwind database before finalizing any changes to the local DataTable object. A couple of factors underlie this order of operation, including the need to confirm entry in the database before finalizing a change in the local DataTable object. In the case of an insert into a table with an autonumber primary key, another consideration is recovering the database autonumber field value before finalizing the insert in a local DataTable object. After the insert, the Button6_Click procedure restores browsing functionality so that text boxes show the currently selected row from the Shippers DataTable object.

The operation of the Delete and Update buttons ( Button7 and Button8 ) is more straightforward than that for inserting new rows. Simply use the browsing buttons to navigate to a record. To delete an item, just click the Delete button to delete the row showing on the form. To update an item, change a column value showing in a text box and then click Update.

What the Application Does

Figure 9-14 shows the application in operation. When the application opens, the form shows the first row in the Shippers DataTable object. Clicking Button4 (>>) displays the last row in the Shippers DataTable object. The top left window in Figure 9-14 shows Form3 just after a click to Button4 .

click to expand
Figure 9-14: A Windows form in a Visual Basic .NET application can enable browsing and manipulating of data in an Access database.

Clicking Button5 (Blank) clears the form so that you can enter a new row in the Northwind database s VBDotNetShippers table and the corresponding local DataTable object. The top right window in Figure 9-14 shows the form just before the entry of the data for a new shipper. Notice that the ShipperID text box is blank. This is because the ShipperID autonumber field value is not determined from within the Visual Basic .NET application. Instead, the ShipperID column gets its value from the Northwind database. Clicking the Insert button in the top right window sends the proposed row from the local DataTable object to the database, retrieves an autonumber field value, and finalizes the proposed value in the local DataTable object while assigning the correct ShipperID value. Therefore, after clicking Insert, the ShipperID value shows a 4 if that is the next autonumber field value for the VBDotNetShippers table.

The bottom left window in Figure 9-14 shows the form immediately after a click to the Delete button with the CAB, Inc. shipper showing. The click removes the row for CAB, Inc. in both the VBDotNetShippers table within the Northwind database and its matching local DataTable object. Therefore, the window shows the last row before the entry of the CAB, Inc. shipper ”namely the row for Federal Shipping.

The bottom right window in Figure 9-14 reveals the row for Federal Shipping immediately after an update of its name. (Notice the X appended to it.) You can make a change by navigating to a row and performing an edit, such as the one shown in the bottom right window. The edit registers in the local DataTable as a proposed row as soon as a user navigates to a new row or clicks the Update button. Clicking the Update button ( Button8 ) can propagate the proposed change from the local DataTable object to the corresponding table in the Northwind database.

Whenever you modify a DataTable object in a disconnected dataset connecting to a database table, the possibility of a concurrency conflict exists if more than one user can modify the database. Therefore, you should either restrict changes to just one user such as a database administrator or code your application so that it can handle concurrency conflicts between a local DataTable object and a database table. To keep the focus on basic data manipulation techniques in Windows Forms, this sample assumes changes will be made by a single user. See Chapter 8 for a more in-depth discussion of concurrency violation issues along with a sample demonstrating how to handle concurrency violations.

The Form Load Event Procedure

The following listing shows the form load event procedure along with the module-level variables for the code behind Form3 . The three variables declared at the module level are dap1 , das1 , and cnn1 . The dap1 variable points at a data adapter that serves to coordinate the contents of the local Shippers DataTable object with the VBDotNetShippers table in the Northwind database. The major function of the form load event procedure is to configure the OleDbDataAdapter object at which dap1 points. The das1 variable refers to the dataset that contains the local Shippers DataTable object. The das1 variable plays a role in every data function, from initially populating the local DataTable object to deleting rows. The cnn1 variable points at the connection to the Northwind database from the Visual Basic .NET application. The configuration of the dap1 variable in the form load event procedure relies on references to the cnn1 variable, and the event procedure that populates the local DataTable with the autonumber field value for new rows also uses the cnn1 variable.

The Form3_Load procedure accomplishes four data management goals:

  • Configuring the OleDbDataAdapter for browsing and data manipulation

  • Initially filling the Shippers DataTable object with values from the VBDotNetShippers table in the Northwind database

  • Adding a primary key constraint to the Shippers DataTable object

  • Binding the form s text boxes to DataColumn objects in the Shippers DataTable object

Beyond these data- related goals, the load event procedure formats the controls on Form3 by performing actions such as assigning Text property values, making TextAlign property settings, and setting the ReadOnly property of TextBox1 to True . To conserve space and keep the focus on ADO.NET tasks , the listing in the book does not show the formatting code. See the Form3_Load procedure in the DatasetForms project for the complete procedure listing.

The most sophisticated task for the load event procedure is configuring the OleDbDataAdapter for browsing and data manipulation. The procedure configures the data adapter represented by the dap1 variable with a series of four main property assignments. These properties are named SelectCommand , InsertCommand , DeleteCommand , and UpdateCommand . You can use each property to get or set an OleDbCommand object associated with the dap1 OleDbDataAdapter . The OleDbCommand constructor used in the sample to make property assignments takes two arguments. One argument specifies a Jet SQL string designating a data command, such as a SELECT, an INSERT, a DELETE, or an UPDATE statement.

Configuring the InsertCommand , DeleteCommand , or UpdateCommand properties for a data adapter requires parameters for the passing of values between a local DataTable object and a database object. The code behind the data manipulation buttons updates the local DataTable object to establish proposed changes, coordinates these changes to the DataTable object with the corresponding Northwind database object (the VBDotNetShippers table), and finalizes the changes to the local DataTable object. For the DELETE and UPDATE data commands in the current sample, it is necessary to coordinate one or more column values in a DataTable object with the same column values in an Access database table or query. For example, you can t update a column value in a row that another user removed from an Access database table. Attempting to perform this task generates a concurrency violation. Similarly, trying to delete a row previously deleted by another user generates a concurrency violation. The INSERT data command is not subject to a concurrency violation because the Access database assigns a unique autonumber field value to each row just before committing the row to a database object.

The SelectCommand property specifies the data available to fill a local DataTable object. In the sample code, the procedure designates all columns for all rows. However, you can designate a subset of both the columns and the rows in an Access data source. If you are not comfortable writing Jet SQL, use the graphical query designer in Access to formulate a query, and then copy the code in the SQL view to the constructor statement for the OleDbCommand object specifying the SelectCommand property. The second argument for the OleDbCommand constructor specifying the SelectCommand , InsertCommand , DeleteCommand , and UpdateCommand properties for the dap1 OleDbDataAdapter is the cnn1 variable that points at the Northwind database. (See the module-level declarations.)

Note  

The Visual Studio .NET Data Adapter Configuration Wizard exists to help define queries for an OleDbDataAdapter object. However, it fails for selected Access queries, such as joins for three tables. Therefore, a good practice is to systematically use the query designer in Access for assistance in developing queries.

The OleDbCommand object for the InsertCommand property of dap1 uses the INSERT INTO keywords to specify a row of values from a local DataTable for insertion into an Access database through a table or query. In the context of this sample, the values are for the CompanyName and Phone columns in the VBDotNetShippers table of the Northwind database. You need a parameter for each value that you intend to transfer from a DataTable object in a Visual Basic .NET application to a table or a query in an Access database file. Use the Add method for the Parameters collection of an OleDbDataAdapter s InsertCommand object to specify a parameter for a column value. The Form3_Load procedure shows the syntax for this method in the current application. The Add method arguments designate, in order, the parameter name, the data type, the length of the parameter, and the name of the column in a database to receive the parameter value.

After specifying the InsertCommand property for dap1 , the procedure shows the syntax for designating a DeleteCommand property. If you are deleting just one row at a time, you will want to specify a DELETE statement with a WHERE clause designating via a primary key the current row showing on the form. When the primary key is an autonumber field, as in the VBDotNetShippers table, you can specify just one column as the argument for the WHERE clause.

Specifying an UpdateCommand property for an OleDbDataAdapter object requires parameters for each column value for which you permit an update. In the sample application, these are the CompanyName and Phone columns. Users cannot update the ShipperID column values because these are autonumber fields that Access manages. In the sample application, the UpdateCommand object permits the update to succeed as long as the primary key in a local DataTable object matches a corresponding primary key value in an Access table. At your option, you can specify more rigid criteria for an update to succeed. The UpdateCommand object specifies a SourceVersion property for the parameter designating the ShipperID in the WHERE clause of its CommandText property. The SourceVersion property is set to Original . This setting designates a match on the original value from the local DataTable object with the Northwind table. The setting is not strictly necessary in the context of this problem because users cannot change the ShipperID value. (The ShipperID text box has a ReadOnly property setting of True .) When a user can change the primary key (for example, when you are not using autonumber field values for a primary key), assigning the SourceVersion property is critical. The SourceVersion property for a parameter allows your application to have a new primary key value but to match on the original primary key value.

The remaining three blocks of code shown in the listing for this procedure are straightforward (or at least relatively familiar). First, a Fill method populates the Shippers DataTable object in the das1 dataset based on the current values in the VBDotNetShippers table in the Northwind database. At this point, the procedure designates the name for the DataTable in the das1 dataset. Second, the Form3_Load procedure assigns a primary key to the Shippers DataTable object. Third, the listing closes with three additional statements that bind the Text property setting for TextBox1 through TextBox3 to a DataColumn in the Shippers DataTable object. You add a DataBinding object to a control by specifying three arguments: the name of the control s property, the name of the dataset holding the data source, and the name of a DataColumn object within the DataTable object.

Note  

Form controls have a collection of DataBinding objects because the .NET Framework enables the binding of various data sources to multiple form control properties.

 Dim dap1 As New System.Data.OleDb.OleDbDataAdapter() Dim das1 As New System.Data.DataSet() Dim cnn1 As New OleDb.OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=c:\Program Files\" & _ "Microsoft Office\Office10\Samples\Northwind.mdb") Private Sub Form3_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ˜Specify SelectCommand property dap1.SelectCommand = New OleDb.OleDbCommand( _ "SELECT * FROM VBDotNetShippers", cnn1) ˜Specify InsertCommand property and parameters dap1.InsertCommand = New OleDb.OleDbCommand( _ "INSERT INTO VBDotNetShippers " & _ "(CompanyName, Phone) " & _ "VALUES (?, ?)", cnn1) Dim prm1 As OleDb.OleDbParameter = _ dap1.InsertCommand.Parameters.Add("@CompanyName", _ OleDb.OleDbType.VarChar, 40, "CompanyName") Dim prm2 As OleDb.OleDbParameter = _ dap1.InsertCommand.Parameters.Add("@Phone", _ OleDb.OleDbType.VarChar, 24, "Phone") ˜Specify DeleteCommand property and parameters dap1.DeleteCommand = New OleDb.OleDbCommand( _ "DELETE FROM VBDotNetShippers " & _ "WHERE ShipperID = ?", cnn1) Dim prm3 As OleDb.OleDbParameter = _ dap1.DeleteCommand.Parameters.Add("@ShipperID", _ OleDb.OleDbType.Integer) prm3.SourceColumn = "ShipperID" ˜Specify UpdateCommand property and parameters dap1.UpdateCommand = _ New OleDb.OleDbCommand("UPDATE VBDotNetShippers " & _ "SET CompanyName = ?, Phone = ? " & _ "WHERE ShipperID = ?", cnn1) Dim prm4 As OleDb.OleDbParameter = _ dap1.UpdateCommand.Parameters.Add("@CompanyName", _ System.Data.OleDb.OleDbType.VarWChar, 40, "CompanyName") Dim prm5 As OleDb.OleDbParameter = _ dap1.UpdateCommand.Parameters.Add("@Phone", _ System.Data.OleDb.OleDbType.VarWChar, 24, "Phone") Dim prm6 As OleDb.OleDbParameter = _ dap1.UpdateCommand.Parameters.Add( _ New System.Data.OleDb.OleDbParameter("@oldShipperID", _ OleDb.OleDbType.Integer)) prm6.SourceColumn = "ShipperID" prm6.SourceVersion = DataRowVersion.Original ˜Fill the Shippers table dap1.Fill(das1, "Shippers") ˜Define a primary key for the DataTable object das1.Tables(0).PrimaryKey = _ New DataColumn() {das1.Tables(0).Columns("ShipperID")} ˜Bind the text boxes TextBox1.DataBindings.Add("Text", das1, _ "Shippers.ShipperID") TextBox2.DataBindings.Add("Text", das1, _ "Shippers.CompanyName") TextBox3.DataBindings.Add("Text", das1, _ "Shippers.Phone") ... End Sub 

Browsing Through Rows

To delete or update a row, this application requires you to browse to that row. The click event procedures for Button1 through Button4 enable browsing. (See Figure 9-13 for the positions of these buttons on Form3 .) Adding a DataBinding object to a TextBox control enables you to browse column values in a DataTable object for the bound control. In this case, the bound objects are the DataColumn objects in the Shippers DataTable object. As mentioned, the Form3_Load procedure links TextBox1 with the ShipperID DataColumn object, TextBox2 with the CompanyName DataColumn object, and TextBox3 with the Phone DataColumn object.

Your application can change the row shown from a DataTable object by modifying the Position property for the BindingContext object associated with a dataset and a DataTable object. Any one form can have multiple BindingContext objects associated with various DataTable objects. When a form opens, all bound controls show the first position, or row, in the data source to which those controls bind. This corresponds to Position property value of 0. You can move bound controls to the first position in a DataTable at any time during a session by setting the Position property to 0. The Button1_Click procedure implements this approach for navigating to the first row in the Shippers Data Table object. Increase the Position property value for a BindingContext object by 1 to move to the next row or decrease the Position property value by 1 to move to the preceding row. The click event procedures for Button2 and Button3 move backward and forward through the Shippers DataTable by subtracting and adding 1 to the current Position property value. The Count property reflects the total number of rows in the DataTable to which a control binds through the DataBinding property. By subtracting 1 from the Count property value for a BindingContext object, you can specify the Position value for the last row in a DataTable. The Button4_Click event procedure uses this feature to navigate to the last row in the Shippers DataTable object.

 Private Sub Button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles Button1.Click ˜Move to first position Me.BindingContext(das1, "Shippers").Position _ = 0 End Sub Private Sub Button2_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles Button2.Click ˜Move to previous position Me.BindingContext(das1, "Shippers").Position _ -= 1 End Sub Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click ˜Move to next position Me.BindingContext(das1, "Shippers").Position _ += 1 End Sub Private Sub Button4_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button4.Click ˜Move to last position Me.BindingContext(das1, "Shippers").Position = _ Me.BindingContext(das1, "Shippers").Count - 1 End Sub 

Inserting a New Row

Three event procedures handle the insertion of a new row into the local Shippers DataTable object and the corresponding insertion into the VBDotNetShippers table in the Northwind database. Two of these event procedures apply to the Button5 and Button6 click events. The third event procedure applies to the RowUpdated event. The .NET Framework raises this event after it executes a data command against a data source, such as the VBDotNetShippers table in the Northwind database. The Button5_Click procedure prepares the form for the entry of a new row of data. The Button6_Click procedure invokes the Update method to transfer a new row from the Shippers DataTable object to the VBDotNetShippers table in the Northwind database. The OnRowUpdated procedure handles the RowUpdated event to populate the local DataTable object with the primary key autonumber field value assigned by the Access database. This step is necessary to keep the primary key in the DataTable object synchronized with the primary key in the Northwind VBDotNetShippers table.

To use Form3 for data entry, be sure its text box controls are unbound from the DataColumn objects in the Shippers DataTable object. You can achieve this result by invoking the Clear method for the DataBindings collection associated with each text box. Typically, you will want to enter a new row of column values. Therefore, the sample application clears the Text property settings of each text box with the object s Clear method. The Button5_Click procedure demonstrates the syntax for both actions.

After the Button5_Click procedure readies the form for data entry, a user can input a new set of column values. However, the application needs to enable users to transfer values from the form to the local DataTable object, and the application needs to pass the values from the local DataTable object to the database associated with the DataTable object through the dap1 OleDbDataAdapter . The InsertCommand object for the dap1 data adapter moderates the transfer of information from the Shippers DataTable object to the VBDotNetShippers table in the Northwind database. The Button6_Click procedure invokes the Update method for the dap1 data adapter to launch the exchange of information between the local DataTable object and the database table.

After the exchange completes, the .NET Framework raises the RowUpdated event. Through an AddHandler statement, the Button6_Click procedure designates the OnRowUpdated procedure as the delegate for handling the event. After the launching of the Update method and the handling of the RowUpdated event, the Button6_Click procedure closes by reestablishing the DataBinding settings for the text boxes and moving to the last row in the local DataTable . These final steps enable Form3 to show the most recently added row.

When the application invokes the OnRowUpdated procedure, it receives the current row of column values in its args argument. The objective for the procedure in this application is to retrieve the autonumber field for the most recently inserted row in the Access database. Starting with Access 2000, Jet SQL acquired the @@IDENTITY statement for achieving this very task within a SELECT statement. Therefore, the OnRowUpdated procedure creates an OleDbCommand object with the SELECT statement as its CommandText property and the cnn1 connection object specified at the module level. Invoking the ExecuteScalar method for the OleDbCommand object returns the last autonumber field value. Before closing, the procedure assigns the returned autonumber field value to the ShipperID column in the local Shippers DataTable object. This assignment synchronizes the primary key values for the new row in the Northwind database table and its corresponding local DataTable object.

 Private Sub Button5_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button5.Click ˜Remove bindings for text boxes TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() ˜Clear text boxes for entry of new row TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() End Sub Private Sub Button6_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button6.Click ˜Add the row locally with any arbitrary value for ˜its ShipperID column value; the sample specifies ˜a ShipperID value of the maximum Integer data ˜value Dim drw1 As DataRow = _ das1.Tables("Shippers").NewRow() drw1("CompanyName") = TextBox2.Text drw1("Phone") = TextBox3.Text drw1("ShipperID") = Integer.MaxValue das1.Tables("Shippers").Rows.Add(drw1) ˜Include an event to fill in the autonumber value AddHandler dap1.RowUpdated, _ New OleDb.OleDbRowUpdatedEventHandler( _ AddressOf OnRowUpdated) ˜Update the Access database file dap1.Update(das1, "Shippers") ˜Re-bind text boxes to columns in Shippers DataTable object TextBox1.DataBindings.Add("Text", das1, _ "Shippers.ShipperID") TextBox2.DataBindings.Add("Text", das1, _ "Shippers.CompanyName") TextBox3.DataBindings.Add("Text", das1, _ "Shippers.Phone") ˜Move to last row in Shippers DataTable object Me.BindingContext(das1, "Shippers").Position = _ Me.BindingContext(das1, "Shippers").Position.MaxValue End Sub Private Sub OnRowUpdated(ByVal sender As Object, _ ByVal args As OleDb.OleDbRowUpdatedEventArgs) ˜Include a variable and a command to retrieve the ˜identity value from the Access database Dim int1 As Integer = 0 Dim cmd1 As OleDb.OleDbCommand = _ New OleDb.OleDbCommand("SELECT @@IDENTITY", cnn1) If args.StatementType = StatementType.Insert Then ˜Retrieve the identity value and ˜store it in the ShipperID column int1 = CInt(cmd1.ExecuteScalar()) args.Row("ShipperID") = int1 End If End Sub 

Deleting the Currently Selected Row

The Delete method allows you to mark a row for deletion from a DataTable object. The next invocation of the Update method removes the matching row from a table in an Access database file and finalizes the proposed change to the local DataTable object. In Chapter 8, you learned that the Delete method applies to a Rows collection member. That chapter showed you how to use the Delete method with the Find method. However, you need a primary key constraint in a DataTable object to invoke the Find method. A more robust implementation that does not require a primary key is to use the Find method associated with a DataView object.

Using this method gives me an opportunity to introduce you to the DataView object, which roughly parallels a view or query in Access. For the DataView object s Find method to work, the DataView object must be sorted by the column values for the field on which you want to perform a find. The Button7_Click procedure shows the syntax for achieving these tasks in the context of the current sample application. After invoking the Delete method for the row index discovered with the DataView object, the Button7_Click procedure invokes the Update method for the dap1 OleDbDataAdapter . This removes the corresponding row from the VBDotNetShippers table in the Northwind database and finalizes, or accepts, the proposed change to the local DataTable object.

 Private Sub Button7_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button7.Click ˜Create sorted DataView object Dim dav1 As DataView = New DataView(das1.Tables("Shippers")) dav1. Sort = "ShipperID" ˜Use DataView object to return row index for currently ˜selected row and delete row from DataTable object that is ˜the source for the DataView object Dim int1 As Integer = dav1.Find(CInt(TextBox1.Text)) das1.Tables("Shippers").Rows(int1).Delete() ˜Invoke Update method to finalize deleted row in database ˜file and DataTable object dap1.Update(das1, "Shippers") End Sub 

Updating a Row

The final procedure in the sample, Button8_Click , processes the updating of a row both in the local DataTable object and the matching table in the Northwind database. The processing of an update is straightforward. First, you have to commit the proposed change. Second, you invoke the Update method to transfer the change through the UpdateCommand property for an OleDbDataAdapter to the database that the data adapter connects to. To commit the edited value in the form as a proposed change, you can move off and return to the current row in the DataTable object. The DataBinding objects automatically transfer the form text box values to the local DataTable object pointed at by the DataBinding objects. If you happen to be on the first row ( Position property equals 0), you can just attempt to move forward one row.

Although the .NET Framework does not actually revise the value showing in the text boxes, it does update the local DataTable object with the form text box values. After revising the local DataTable object, the next step is to transfer the change to the table in the Northwind database file. This can be as easy as invoking the Update method. You can resolve any possible concurrency violations by adapting the techniques described at the end of Chapter 8. Perhaps the easiest way to avoid concurrency violations is to allow updates only by a designated database administrator.

 Private Sub Button8_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button8.Click ˜Move off current row to propose update If Me.BindingContext(das1, "Shippers").Position = 0 _ Then Me.BindingContext(das1, "Shippers").Position -= 1 Else Me.BindingContext(das1, "Shippers").Position -= 1 Me.BindingContext(das1, "Shippers").Position += 1 End If ˜Invoke Update method to commit change in database file ˜and DataTable object dap1.Update(das1, "Shippers") End Sub 
 


Programming Microsoft Visual Basic. NET for Microsoft Access Databases
Programming Microsoft Visual Basic .NET for Microsoft Access Databases (Pro Developer)
ISBN: 0735618194
EAN: 2147483647
Year: 2006
Pages: 111
Authors: Rick Dobson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net