Master C# Logo banner
Welcome to MasterCSharp.com - Master C#, the easy way... - by Saurabh Nandu

 


BookStock v3- Samples to Show Simple OleDb Managed Provider Interaction

Add Comment
 

 
<div align="center"> <table border="0" width="70%" class="outline"> <tr> <td width="25%" class="outline"><b>Download File</b></td> <td width="25%" class="outline"><b>SDK Version</b></td> </tr> <tr> <td width="25%" class="outline"><a class="wbox" href="../../file/bookstockv3.zip">bookstockv3.zip</a> (31kb)</td> <td width="25%" class="outline">v1.0.3705</td> </tr> </table> </div> <p> <span class="wboxheado">Introduction</span><br> The Book Stock examples described in this article, are three Windows Forms applications that perform various operations like Inset / Update / Delete with Ms Access database using the OleDb Managed Provider.</p> <p><span class="wboxheado">Requirements</span><br> 1) .NET SDK v1 (1.0.3705) (This example might not work with the other versions.)<br> 2) Ms Access 2000 (Optional, required only if you want to change the database design.)</p> <span class="wboxheado">Database Schema</span><table border="0" width="90%" class="Outline"> <tr> <td width="100%" colspan="3" class="Outline"> <span class="wboxhead">Table Name - bookstock / File Name - book.mdb</span></td> </tr> <tr> <td width="20%" class="Outline"><b>Column Name</b></td> <td width="15%" class="Outline"><b>Data Type</b></td> <td width="65%" class="Outline"><b>Description</b></td> </tr> <tr> <td width="20%" class="Outline">bookid</td> <td width="15%" class="Outline">Integer</td> <td width="65%" class="Outline">Primary Key Field. Unique identity number of a book.</td> </tr> <tr> <td width="20%" class="Outline">booktitle</td> <td width="15%" class="Outline">Text</td> <td width="65%" class="Outline">Title of the book.</td> </tr> <tr> <td width="20%" class="Outline">bookauthor</td> <td width="15%" class="Outline">Text</td> <td width="65%" class="Outline">Author of the book.&nbsp;</td> </tr> <tr> <td width="20%" class="Outline">bookprice</td> <td width="15%" class="Outline">Integer</td> <td width="65%" class="Outline">Price of the book.</td> </tr> <tr> <td width="20%" class="Outline">bookstock</td> <td width="15%" class="Outline">Integer</td> <td width="65%" class="Outline">Stock available of the book.</td> </tr> </table> &nbsp; <p> <span class=wboxheado>Code</span><br> 1) <I><b>DataAdd.cs</b> :- Add Records in to the Database (only relevant code shown).<br> </I>This application is a very simple application, the only task it performs is to take data from the user and insert it into the database. I use simple a simple SQL INSERT statement to insert the new book information into the database. I do not perform validation before inserting data into the database, but ideally this should be done.</p> <p><img border="0" src="../../img/bookstockdataadd.gif" width="400" height="400"></p> <table border="0" width="100%" class="Code" cellspacing="0" cellpadding="0"> <tr> <td width="100%"> <pre>namespace SaurabhData { using System; using System.Drawing; using System.Windows.Forms; using System.Data.OleDb; using System.Data; using System.Threading ; <span class=cmt>/// &lt;summary&gt; /// Class to add data in to a Ms Access 2000 database book.mdb /// using OleDb Managed Provider . /// &lt;/summary&gt;</span> public class DataAdd : Form { private System.Windows.Forms.Label title; private System.Windows.Forms.StatusBar statusBar; private System.Windows.Forms.Button helpme; private System.Windows.Forms.Button save; private System.Windows.Forms.TextBox t_bookstock; private System.Windows.Forms.TextBox t_bookprice; private System.Windows.Forms.TextBox t_bookauthor; private System.Windows.Forms.TextBox t_booktitle; private System.Windows.Forms.TextBox t_bookid; private System.Windows.Forms.Label l_bookstock; private System.Windows.Forms.Label l_bookprice; private System.Windows.Forms.Label l_bookauthor; private System.Windows.Forms.Label l_booktitle; private System.Windows.Forms.Label l_bookid; private string strCon = &quot;Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=book.mdb&quot; ; <span class=cmt>///&lt;summary&gt; /// This constructor calls 2 methods InitializeComponent() /// to initialize the Windows Form Components and /// starts a thread on the Method GetConnected() which /// connects to the Database and returns the number of records present ///&lt;/summary&gt;</span> public DataAdd() { InitializeComponent(); <span class=cmt>//put the connection to the database on a Thread so the Form displays quickly..</span> ThreadStart tsgc = new ThreadStart( GetConnected ) ; Thread tgc = new Thread( tsgc ) ; tgc.Start() ; <span class=cmt>//if you don't want to use threading then omit the above //3 lines and add the below line //GetConnected() ;</span> } <span class=cmt>/// &lt;summary&gt; /// Clean up any resources being used /// &lt;/summary&gt;</span> protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } <span class=cmt>/// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt;</span> public static void Main( string[] args ) { Application.Run( new DataAdd() ); } <span class=cmt>///&lt;summary&gt; /// &lt;para&gt; /// Required method to get connected with the Database and update the Book Id. /// text box with the current number of records in the database plus one. /// &lt;/para&gt; ///&lt;/summary&gt;</span> public void GetConnected() { statusBar.Text= &quot;Please Wait, Connecting ....&quot; ; <span class=cmt>//Make the Connection Object</span> OleDbConnection myCon = new OleDbConnection( strCon ) ; <span class=cmt>//Make a Select Command</span> string sqlStr = &quot;SELECT bookid FROM bookstock ORDER BY bookid DESC&quot; ; OleDbCommand myCmd =new OleDbCommand( sqlStr , myCon ); try { myCon.Open(); int recordCount = (Int16) myCmd.ExecuteScalar(); <span class=cmt>//update the Book Id textbox with the Number of records present plus one.</span> recordCount++; t_bookid.Text = recordCount.ToString() ; statusBar.Text=&quot;Connected - Now you can add records&quot;; } catch(Exception e) { MessageBox.Show(&quot;Error in connecting! &quot;+e.ToString(), &quot;Error&quot;); } finally { myCmd.Dispose(); myCon.Close(); myCon.Dispose(); } } <span class=cmt>/// &lt;summary&gt; /// Initialize the various components of the Form /// &lt;/summary&gt;</span> private void InitializeComponent() { <span class="Cmt">//The code here is used to design the form //Please download the file for the complete code</span> } <span class=cmt>///&lt;summary&gt; /// &lt;para&gt; /// This method is called when the &quot;Save&quot; Button is Clicked. /// It checks if Data is entered into all the fields, and then it proceeds /// with opening an connection whit the database and ///inserting the new data in it. /// &lt;/para&gt; ///&lt;/summary&gt;</span> protected void saveClick(object sender, System.EventArgs e) { <span class=cmt>//code to save the inputted data in to the database //no code to validate the data implemented</span> if( t_bookid.Text != &quot;&quot; &amp;&amp; t_booktitle.Text != &quot;&quot; &amp;&amp; t_bookauthor.Text != &quot;&quot; &amp;&amp; t_bookprice.Text != &quot;&quot; &amp;&amp; t_bookstock.Text != &quot;&quot; ) { OleDbConnection myCon = new OleDbConnection( strCon ) ; <span class=cmt>//the string to get values from the textboxes and form an &quot;INSERT INTO&quot; // statement.</span> string sqlStr = &quot;INSERT INTO bookstock (bookid, booktitle, bookauthor, bookprice, bookstock) VALUES ( &quot;; sqlStr += this.ToSQL( t_bookid.Text ) +&quot;, '&quot;; sqlStr += this.ToSQL( t_booktitle.Text ) +&quot;', '&quot;; sqlStr += this.ToSQL( t_bookauthor.Text ) +&quot;', &quot;; sqlStr += this.ToSQL( t_bookprice.Text ) +&quot;, &quot;; sqlStr += this.ToSQL( t_bookstock.Text ) +&quot;)&quot;; OleDbCommand myCmd = new OleDbCommand( sqlStr , myCon ) ; try { myCon.Open(); <span class=cmt>//Execute the statement </span> myCmd.ExecuteNonQuery() ; statusBar.Text=&quot;Data added to database&quot; ; <span class=cmt>//reset all the textboxes</span> int recordCount =int.Parse( t_bookid.Text ); recordCount++ ; t_bookid.Text= recordCount.ToString() ; t_booktitle.Text=&quot;&quot; ; t_bookauthor.Text=&quot;&quot; ; t_bookprice.Text=&quot;&quot; ; t_bookstock.Text=&quot;&quot; ; statusBar.Text=&quot;Connected - Now you can add records&quot;; } catch( Exception ed ) { MessageBox.Show(&quot;Error in inserting! &quot;+ed.ToString(), &quot;Error&quot;); } finally { myCmd.Dispose(); myCon.Close() ; myCon.Dispose(); } } else { MessageBox.Show(&quot;All fields must be completed.&quot;, &quot;Error&quot;); } } <span class=cmt>/// &lt;summary&gt; /// This method is used to convert the input string into a valid /// SQL syntax by escaping a single quote (') by 2 single quotes ('') /// &lt;/summary&gt; /// &lt;param name=&quot;input&quot;&gt;input string&lt;/param&gt; /// &lt;returns&gt;quoted string&lt;/returns&gt;</span> private string ToSQL( string input ) { return input.Replace( &quot;'&quot; , &quot;''&quot; ); } } } </pre> <pre>&nbsp;</pre> </td> </tr> </table> <P>&nbsp;</P> <P>2)<I> <b>DataView.cs</b>:- View Records from Database and DataBind (Only relevant code).<br> </I>This is a slightly more complex application, it allows you to navigate to the first, previous, next and last positions within the database. In this example I have <b>Data Bound</b> the TextBoxes to the DataSet object. <b>Data Binding</b> enables you to <i>synchronize</i> the Data between the <b>UI </b>(User Interface) and the <b>Data Source</b>. Please note that when I say <b>Data Source</b> I am not referring to only a database, in the new Windows Forms API you can data bind Controls to various data sources like arrays, collections , DataSet's, DataTable's etc.</P> <P>The <b>BindingManagerBase</b> class from the <i>System.Windows.Forms</i> namespace is used to <i>synchronize</i> all the controls within a <i>Container Control</i> (generally Form Control, but it can be Panel Control, GroupBox Control etc also) that bind to the same <i>Data Source</i>. Hence in my example since all TextBoxes on my <b>Form</b> are data bound to same DataSet object, I just increment / decrement the <b>Position</b> property of the <i>BindingManagerBase</i> object and all the TextBoxes are updated accordingly. </P> <P>The <b>BindingContext</b> class from the <i>System.Windows.Forms</i> namespace, is used to manage all the different <i>BindingManagerBase</i> objects (and its child classes like <i>CurrencyManager</i>) for a given Control. <br> So for example, you have various controls on your <i>Form</i> that data bind to various <i>different</i> data sources, you can use the <i>BindingContext</i> object of the <i>Form</i> to get a reference to the <i>BindingManagerBase</i> objects <i>for each</i> data source.</P> <P><I> <img border="0" src="../../img/bookstockdataview.gif" width="400" height="400"></I></P> <table border="0" width="100%" class="Code"> <tr> <td width="100%"> <pre>namespace SaurabhData { using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; using System.Data.OleDb; using System.Data; <span class=cmt>/// &lt;summary&gt; /// Class to demonstrate how to view data from a database using OleDb Managed Provider ///This example also uses Data Binding. /// &lt;/summary&gt;</span> public class DataView : System.Windows.Forms.Form { private System.Windows.Forms.Button helpme; private System.Windows.Forms.Button lastrec; private System.Windows.Forms.Button nextrec; private System.Windows.Forms.Button previousrec; private System.Windows.Forms.Button firstrec; private System.Windows.Forms.TextBox t_bookstock; private System.Windows.Forms.TextBox t_bookprice; private System.Windows.Forms.TextBox t_bookauthor; private System.Windows.Forms.TextBox t_booktitle; private System.Windows.Forms.TextBox t_bookid; private System.Windows.Forms.Label l_bookstock; private System.Windows.Forms.Label l_bookprice; private System.Windows.Forms.Label l_bookauthor; private System.Windows.Forms.Label l_booktitle; private System.Windows.Forms.Label l_bookid; private System.Windows.Forms.Label label1; private System.Windows.Forms.StatusBar statusBar; private System.Data.DataSet myDataSet ; private BindingManagerBase myBind; <span class=cmt>///&lt;summary&gt; /// This is the constructor of the class which calls 2 methods. /// GetConnected() to connect to the database and get the data /// from the database. /// InitilizeComponents() this method is called to initialize the form components. ///&lt;/summary&gt;</span> public DataView() { //Connect to the Database. GetConnected() ; InitializeComponent(); } <span class=cmt>/// &lt;summary&gt; /// Clean up any resources being used /// &lt;/summary&gt;</span> protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } <span class=cmt>/// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt;</span> public static void Main(string[] args) { Application.Run(new DataView()); } <span class=cmt>///&lt;summary&gt; /// This method connects to the database and returns a Dataset Object. ///&lt;/summary&gt;</span> public void GetConnected() { string strCon = &quot;Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=book.mdb&quot; ; string sqlStr = &quot;SELECT * FROM bookstock&quot; ; <span class=cmt>//make a OleDbConnection object</span> OleDbConnection myCon =new OleDbConnection( strCon ) ; <span class=cmt>//Make a DataSet object</span> myDataSet = new DataSet() ; try { <span class=cmt>//Using the OleDbDataAdapter execute the query</span> OleDbDataAdapter myAdapter = new OleDbDataAdapter( sqlStr , myCon ) ; <span class=cmt>//Fill the DataSet with the Table 'bookstock'</span> myAdapter.Fill(myDataSet,&quot;bookstock&quot;) ; myAdapter.Dispose(); } catch(Exception e) { MessageBox.Show(&quot;Error in connecting! &quot;+e.ToString(), &quot;Error&quot;); } finally { <span class=cmt>//Close the OleDbConnection</span> myCon.Close() ; myCon.Dispose(); } } private void InitializeComponent() { <span class="Cmt">//The code here is used to design the form //Please download the file for the complete code </span> <span class=cmt>//DataBind the TextBox using the &quot;DataBindings&quot; property of the //TextBox control. Since we are Data Binding to the &quot;Text&quot; property //of the TextBox we pass it as the first parameter //The DataSet object is passed as the second parameter //The Table Name with the Field Name is passed as the third parameter</span> t_bookid.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookid&quot;); t_bookstock.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookstock&quot;); t_booktitle.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.booktitle&quot;); t_bookprice.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookprice&quot;); t_bookauthor.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookauthor&quot;); <span class=cmt>//Get the BindingManagerBase object for this data source</span> myBind= this.BindingContext [myDataSet, &quot;bookstock&quot;]; } <span class=cmt>///&lt;summary&gt; /// To navigate the BindingManagerBase, increment the Position property. ///&lt;/summary&gt; </span> private void MoveNext() { if (myBind.Position == myBind.Count -1) MessageBox.Show(&quot;End of records&quot;); else myBind.Position += 1; } <span class=cmt>///&lt;summary&gt; /// To navigate the BindingManagerBase, increment the Position property. ///&lt;/summary&gt;</span> private void MovePrevious(){ if (myBind.Position == 0) MessageBox.Show(&quot;First record&quot;); else myBind.Position -= 1; } <span class=cmt>///&lt;summary&gt; /// Move to position 0 in the list. ///&lt;/summary&gt;</span> private void MoveFirst(){ myBind.Position = 0; } <span class=cmt>///&lt;summary&gt; /// Move to the last position. ///&lt;/summary&gt;</span> private void MoveLast(){ myBind.Position = myBind.Count - 1; } <span class=cmt>///&lt;summary&gt; /// Last Record Button Clicked ///&lt;/summary&gt;</span> protected void GoLast(object sender, System.EventArgs e) { MoveLast(); } <span class=cmt>///&lt;summary&gt; /// Next Record Button Clicked ///&lt;/summary&gt;</span> protected void GoNext(object sender, System.EventArgs e) { MoveNext(); } <span class=cmt>///&lt;summary&gt; /// Previous Record Button Clicked ///&lt;/summary&gt;</span> protected void GoPrevious(object sender, System.EventArgs e) { MovePrevious(); } <span class=cmt>///&lt;summary&gt; /// First Record Button Clicked ///&lt;/summary&gt;</span> protected void GoFirst(object sender, System.EventArgs e) { MoveFirst(); } } }</pre> </td> </tr> </table><P>&nbsp;</P> <P>3) <I><b>DataEdit.cs</b> :- View, Edit, Delete Records in to the Database (only relevant code shown).<br> </I>The last application of this example shows you the actual benefits of <i>Data Binding</i> your Windows Forms Controls. In this example besides enabling record navigation (as shown in above application), you can also <i>Update</i> and <i>Delete</i> records. <br> As I said earlier Data Binding helps synchronize the data between the UI and the data source, so as soon as you make any update/changes to as of the records (TextBoxes) and click any button the changes are <i>persisted</i> back to the data source, a DataSet in our case, from then its in your hands if you want to reconcile the DataSet with the DataBase or not. </P> <P>One important point to note is that while Data Binding to <i>multiple controls</i> always call the <b>EndCurrentEdit</b> method of the <b>BindingManagerBase</b> class indicating that you have finished making the changes before updating the database. <br> In case you fail to call the <i>EndCurrentEdit</i> method and your Data Source is a DataSet the changes will get reflected in the DataSet, but the <b>RowState</b> property of the <b>DataRow</b> that was updated will remain as <b>Unchanged</b>. Now if you call the <b>Update</b> method (of the OleDbDataAdapter / SqlDataAdapter class) on such a DataSet <b>no changes</b> will be reflected in the database, but if you are writing the result out to a XML file using the <b>WriteXml</b> method (of the DataSet object) then the changes will be correctly reflected.<br> If you call the <i>EndCurrentEdit</i> method then the <i>RowState</i> property of the <i>DataRow</i> that was updated will be changed to <b>Modified</b> and now when you call the <i>Update</i> method (of the OleDbDataAdapter / SqlDataAdapter ) the changes will be correctly reflected in the database, but if you write the changes to a XML file using the <i>WriteXml</i> method (of the DataSet class) these changes will not get reflected.&nbsp; You will have to call the <b>AcceptChanges</b> method on the DataSet if you want these changes to be correctly reflected to your XML file.</P> <P><img border="0" src="../../img/bookstockdataedit.gif" width="400" height="450"></P> <table border="0" width="100%" class="Code"> <tr> <td width="100%"> <pre>namespace SaurabhData { using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; using System.Data.OleDb; using System.Data; <span class=cmt>/// &lt;summary&gt; /// Class for viewing, editing and deleting data in a /// Ms Access 2000 database book.mdb /// &lt;/summary&gt;</span> public class DataEdit : System.Windows.Forms.Form { private System.Windows.Forms.Button delete; private System.Windows.Forms.Button update; private System.Windows.Forms.Button helpme; private System.Windows.Forms.Button lastrec; private System.Windows.Forms.Button nextrec; private System.Windows.Forms.Button previousrec; private System.Windows.Forms.Button firstrec; private System.Windows.Forms.TextBox t_bookstock; private System.Windows.Forms.TextBox t_bookprice; private System.Windows.Forms.TextBox t_bookauthor; private System.Windows.Forms.TextBox t_booktitle; private System.Windows.Forms.TextBox t_bookid; private System.Windows.Forms.Label l_bookstock; private System.Windows.Forms.Label l_bookprice; private System.Windows.Forms.Label l_bookauthor; private System.Windows.Forms.Label l_booktitle; private System.Windows.Forms.Label l_bookid; private System.Windows.Forms.Label label1; private System.Windows.Forms.StatusBar statusBar; private System.Data.DataSet myDataSet ; private BindingManagerBase myBind; private string strCon=&quot;Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=book.mdb&quot; ; private OleDbConnection myCon; private OleDbDataAdapter myAdapter ; <span class=cmt>///&lt;summary&gt; /// &lt;para&gt; /// This is the Constructor of the class, it calls 2 methods in it. /// GetConnected()- This method fills the DataSet /// InitializeComponent() - This method initializes the WinForm Components /// &lt;/para&gt; ///&lt;/summary&gt;</span> public DataEdit() { <span class=cmt>//Connect to the Database.</span> GetConnected() ; InitializeComponent(); } <span class=cmt>/// &lt;summary&gt; /// Clean up any resources being used /// &lt;/summary&gt;</span> protected override void Dispose( bool disposing ) { base.Dispose( disposing ); if( myAdapter != null ) myAdapter.Dispose(); if( myCon != null ) myCon.Dispose(); } <span class=cmt>///&lt;summary&gt; /// This method connects to the database and returns a Dataset Object. ///&lt;/summary&gt;</span> public void GetConnected() { <span class=cmt>//make a OleDbConnection object</span> myCon = new OleDbConnection( strCon ) ; string sqlStr = &quot;SELECT * FROM bookstock&quot; ; <span class=cmt>//Make a DataSet object</span> myDataSet = new DataSet() ; <span class=cmt>//Using the OleDbDataAdapter execute the query</span> myAdapter = new OleDbDataAdapter( sqlStr , myCon ) ; <span class=cmt>//Build the Update and Delete SQL Statements</span> OleDbCommandBuilder myBuilder = new OleDbCommandBuilder( myAdapter ); try { <span class=cmt>//Fill the DataSet with the Table 'bookstock'</span> myAdapter.Fill(myDataSet,&quot;bookstock&quot;) ; } catch(Exception e) { MessageBox.Show(&quot;Error in connecting! &quot;+e.ToString(), &quot;Error&quot;); } } <span class=cmt>/// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt;</span> public static void Main(string[] args) { Application.Run(new DataEdit()); } private void InitializeComponent() { <span class="Cmt">//The code here is used to design the form //Please download the file for the complete code </span> <span class=cmt>//Since we are Binding to the Text property of the TextBox we //pass it as the first parameter //As the second parameter we pass the DataSet object //The third parameter contains the Table Name followed by the Field Name //to which the control will data bind</span> t_bookid.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookid&quot;); t_booktitle.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.booktitle&quot;); t_bookauthor.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookauthor&quot;); t_bookprice.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookprice&quot;); t_bookstock.DataBindings.Add(&quot;Text&quot;, myDataSet, &quot;bookstock.bookstock&quot;); <span class=cmt>//Set the BindingManagerBase //Pass the DataSet object and the TableName to bind</span> myBind= this.BindingContext [myDataSet, &quot;bookstock&quot;]; } <span class=cmt>///&lt;summary&gt; /// Delete Button Clicked /// &lt;para&gt; /// This first deletes the row from the DataSet object and then /// It updates the database with the updated DataSet /// &lt;/para&gt; ///&lt;/summary&gt;</span> protected void GoDelete(object sender, System.EventArgs e) { <span class=cmt>//Remove the selected record from the DataSet</span> myDataSet.Tables[0].Rows[myBind.Position].Delete(); <span class=cmt>//Update the database</span> myAdapter.Update( myDataSet , &quot;bookstock&quot; ); } <span class=cmt>///&lt;summary&gt; /// Update Button Clicked /// This method first connects to the database and updates the changes ///&lt;/summary&gt;</span> protected void GoUpdate(object sender, System.EventArgs e) { <span class=cmt>//Its very important to call the EndCurrentEdit method //of the BindingManagerbase while dealing with complex //Databindings, else your changes will not reflect in the //database correctly</span> myBind.EndCurrentEdit() ; <span class=cmt>//Update the database</span> myAdapter.Update( myDataSet , &quot;bookstock&quot; ); } <span class=cmt>///&lt;summary&gt; /// To navigate the ListManager, increment the Position property. ///&lt;/summary&gt; </span> private void MoveNext() { if (myBind.Position == myBind.Count -1) MessageBox.Show(&quot;End of records&quot;); else myBind.Position += 1; } <span class=cmt>///&lt;summary&gt; /// To navigate the ListManager, increment the Position property. ///&lt;/summary&gt;</span> private void MovePrevious(){ if (myBind.Position == 0) MessageBox.Show(&quot;First record&quot;); else myBind.Position -= 1; } <span class=cmt>///&lt;summary&gt; /// Move to position 0 in the list. ///&lt;/summary&gt;</span> private void MoveFirst(){ myBind.Position = 0; } <span class=cmt>///&lt;summary&gt; /// Move to the last position. ///&lt;/summary&gt;</span> private void MoveLast(){ myBind.Position = myBind.Count - 1; } <span class=cmt>///&lt;summary&gt; /// Last Record Button Clicked ///&lt;/summary&gt;</span> protected void GoLast(object sender, System.EventArgs e) { MoveLast(); } <span class=cmt>///&lt;summary&gt; /// Next Record Button Clicked ///&lt;/summary&gt;</span> protected void GoNext(object sender, System.EventArgs e) { MoveNext(); } <span class=cmt>///&lt;summary&gt; /// Previous Record Button Clicked ///&lt;/summary&gt;</span> protected void GoPrevious(object sender, System.EventArgs e) { MovePrevious(); } <span class=cmt>///&lt;summary&gt; /// First Record Button Clicked ///&lt;/summary&gt;</span> protected void GoFirst(object sender, System.EventArgs e) { MoveFirst(); } } }</pre> </td> </tr> </table>

Comments

Add Comment