Public Class FrmBooks Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbSelectCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbInsertCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbUpdateCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDeleteCommand2 As System.Data.OleDb.OleDbCommand Friend WithEvents objBooks As EditBooks.Books Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter Friend WithEvents OleDbDataAdapter2 As System.Data.OleDb.OleDbDataAdapter Friend WithEvents btnLoad As System.Windows.Forms.Button Friend WithEvents btnUpdate As System.Windows.Forms.Button Friend WithEvents btnCancelAll As System.Windows.Forms.Button Friend WithEvents lblAuthor As System.Windows.Forms.Label Friend WithEvents editAuthor As System.Windows.Forms.TextBox Friend WithEvents btnNavFirst As System.Windows.Forms.Button Friend WithEvents btnNavPrev As System.Windows.Forms.Button Friend WithEvents lblNavLocation As System.Windows.Forms.Label Friend WithEvents btnNavNext As System.Windows.Forms.Button Friend WithEvents btnLast As System.Windows.Forms.Button Friend WithEvents btnAdd As System.Windows.Forms.Button Friend WithEvents btnDelete As System.Windows.Forms.Button Friend WithEvents btnCancel As System.Windows.Forms.Button Friend WithEvents grdBooks As System.Windows.Forms.DataGrid Friend WithEvents objTableStylegrdBooksBooks As System.Windows.Forms.DataGridTableStyle Friend WithEvents objColumnStylegrdBooksID As System.Windows.Forms.DataGridTextBoxColumn Friend WithEvents objColumnStylegrdBooksBook As System.Windows.Forms.DataGridTextBoxColumn Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection Friend WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand Private Sub InitializeComponent() Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand() Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection() Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand() Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand() Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand() Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand() Me.OleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand() Me.OleDbUpdateCommand2 = New System.Data.OleDb.OleDbCommand() Me.OleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand() Me.objBooks = New EditBooks.Books() Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter() Me.OleDbDataAdapter2 = New System.Data.OleDb.OleDbDataAdapter() Me.btnLoad = New System.Windows.Forms.Button() Me.btnUpdate = New System.Windows.Forms.Button() Me.btnCancelAll = New System.Windows.Forms.Button() Me.lblAuthor = New System.Windows.Forms.Label() Me.editAuthor = New System.Windows.Forms.TextBox() Me.btnNavFirst = New System.Windows.Forms.Button() Me.btnNavPrev = New System.Windows.Forms.Button() Me.lblNavLocation = New System.Windows.Forms.Label() Me.btnNavNext = New System.Windows.Forms.Button() Me.btnLast = New System.Windows.Forms.Button() Me.btnAdd = New System.Windows.Forms.Button() Me.btnDelete = New System.Windows.Forms.Button() Me.btnCancel = New System.Windows.Forms.Button() Me.grdBooks = New System.Windows.Forms.DataGrid() Me.objTableStylegrdBooksBooks = New System.Windows.Forms.DataGridTableStyle() Me.objColumnStylegrdBooksID = New System.Windows.Forms.DataGridTextBoxColumn() Me.objColumnStylegrdBooksBook = New System.Windows.Forms.DataGridTextBoxColumn() Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection() Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand() CType(Me.objBooks, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.grdBooks, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'OleDbSelectCommand1 ' Me.OleDbSelectCommand1.CommandText = "SELECT ID, Author FROM Authors" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 ' 'OleDbConnection1 ' Me.OleDbConnection1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=SQLBooks;Data Source" & _ "=MHMD;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstati" & _ "on ID=MHMD;Use Encryption for Data=False;Tag with column collation when possible" & _ "=False" ' 'OleDbInsertCommand1 ' Me.OleDbInsertCommand1.CommandText = "INSERT INTO Authors(Author) VALUES (?); SELECT ID, Author FROM Authors WHERE (ID " & _ "= @@IDENTITY)" Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1 Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarChar, 30, "Author")) ' 'OleDbUpdateCommand1 ' Me.OleDbUpdateCommand1.CommandText = "UPDATE Authors SET Author = ? WHERE (ID = ?) AND (Author = ?); SELECT ID, Author " & _ "FROM Authors WHERE (ID = ?)" Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1 Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarChar, 30, "Author")) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarChar, 30, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Author", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Select_ID", System.Data.OleDb.OleDbType.Integer, 4, "ID")) ' 'OleDbDeleteCommand1 ' Me.OleDbDeleteCommand1.CommandText = "DELETE FROM Authors WHERE (ID = ?) AND (Author = ?)" Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1 Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarChar, 30, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Author", System.Data.DataRowVersion.Original, Nothing)) ' 'OleDbSelectCommand2 ' Me.OleDbSelectCommand2.CommandText = "SELECT ID, Book, AuthorID FROM Books" Me.OleDbSelectCommand2.Connection = Me.OleDbConnection1 ' 'OleDbInsertCommand2 ' Me.OleDbInsertCommand2.CommandText = "INSERT INTO Books(Book, AuthorID) VALUES (?, ?); SELECT ID, Book, AuthorID FROM B" & _ "ooks WHERE (ID = @@IDENTITY)" Me.OleDbInsertCommand2.Connection = Me.OleDbConnection1 Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Book", System.Data.OleDb.OleDbType.VarChar, 30, "Book")) Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("AuthorID", System.Data.OleDb.OleDbType.Integer, 4, "AuthorID")) ' 'OleDbUpdateCommand2 ' Me.OleDbUpdateCommand2.CommandText = "UPDATE Books SET Book = ?, AuthorID = ? WHERE (ID = ?) AND (AuthorID = ? OR ? IS " & _ "NULL AND AuthorID IS NULL) AND (Book = ?); SELECT ID, Book, AuthorID FROM Books " & _ "WHERE (ID = ?)" Me.OleDbUpdateCommand2.Connection = Me.OleDbConnection1 Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Book", System.Data.OleDb.OleDbType.VarChar, 30, "Book")) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("AuthorID", System.Data.OleDb.OleDbType.Integer, 4, "AuthorID")) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_AuthorID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AuthorID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_AuthorID1", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AuthorID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Book", System.Data.OleDb.OleDbType.VarChar, 30, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Book", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbUpdateCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Select_ID", System.Data.OleDb.OleDbType.Integer, 4, "ID")) ' 'OleDbDeleteCommand2 ' Me.OleDbDeleteCommand2.CommandText = "DELETE FROM Books WHERE (ID = ?) AND (AuthorID = ? OR ? IS NULL AND AuthorID IS N" & _ "ULL) AND (Book = ?)" Me.OleDbDeleteCommand2.Connection = Me.OleDbConnection1 Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_AuthorID", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AuthorID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_AuthorID1", System.Data.OleDb.OleDbType.Integer, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AuthorID", System.Data.DataRowVersion.Original, Nothing)) Me.OleDbDeleteCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Book", System.Data.OleDb.OleDbType.VarChar, 30, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Book", System.Data.DataRowVersion.Original, Nothing)) ' 'objBooks ' Me.objBooks.DataSetName = "Books" Me.objBooks.Locale = New System.Globalization.CultureInfo("ar-EG") Me.objBooks.Namespace = "http://www.tempuri.org/Books.xsd" ' 'OleDbDataAdapter1 ' Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1 Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1 Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1 Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Authors", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("Author", "Author")})}) Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1 ' 'OleDbDataAdapter2 ' Me.OleDbDataAdapter2.DeleteCommand = Me.OleDbDeleteCommand2 Me.OleDbDataAdapter2.InsertCommand = Me.OleDbInsertCommand2 Me.OleDbDataAdapter2.SelectCommand = Me.OleDbSelectCommand2 Me.OleDbDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Books", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ID", "ID"), New System.Data.Common.DataColumnMapping("Book", "Book"), New System.Data.Common.DataColumnMapping("AuthorID", "AuthorID")})}) Me.OleDbDataAdapter2.UpdateCommand = Me.OleDbUpdateCommand2 ' 'btnLoad ' Me.btnLoad.Location = New System.Drawing.Point(10, 10) Me.btnLoad.Name = "btnLoad" Me.btnLoad.TabIndex = 0 Me.btnLoad.Text = "&Load" ' 'btnUpdate ' Me.btnUpdate.Location = New System.Drawing.Point(145, 10) Me.btnUpdate.Name = "btnUpdate" Me.btnUpdate.TabIndex = 1 Me.btnUpdate.Text = "&Update" ' 'btnCancelAll ' Me.btnCancelAll.Location = New System.Drawing.Point(145, 43) Me.btnCancelAll.Name = "btnCancelAll" Me.btnCancelAll.TabIndex = 2 Me.btnCancelAll.Text = "Ca&ncel All" ' 'lblAuthor ' Me.lblAuthor.Location = New System.Drawing.Point(10, 76) Me.lblAuthor.Name = "lblAuthor" Me.lblAuthor.Size = New System.Drawing.Size(38, 23) Me.lblAuthor.TabIndex = 3 Me.lblAuthor.Text = "Author" ' 'editAuthor ' Me.editAuthor.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objBooks, "Authors.Author")) Me.editAuthor.Location = New System.Drawing.Point(120, 76) Me.editAuthor.Name = "editAuthor" Me.editAuthor.TabIndex = 4 Me.editAuthor.Text = "" ' 'btnNavFirst ' Me.btnNavFirst.Location = New System.Drawing.Point(145, 109) Me.btnNavFirst.Name = "btnNavFirst" Me.btnNavFirst.Size = New System.Drawing.Size(40, 23) Me.btnNavFirst.TabIndex = 5 Me.btnNavFirst.Text = "<<" ' 'btnNavPrev ' Me.btnNavPrev.Location = New System.Drawing.Point(185, 109) Me.btnNavPrev.Name = "btnNavPrev" Me.btnNavPrev.Size = New System.Drawing.Size(35, 23) Me.btnNavPrev.TabIndex = 6 Me.btnNavPrev.Text = "<" ' 'lblNavLocation ' Me.lblNavLocation.BackColor = System.Drawing.Color.White Me.lblNavLocation.Location = New System.Drawing.Point(220, 109) Me.lblNavLocation.Name = "lblNavLocation" Me.lblNavLocation.Size = New System.Drawing.Size(95, 23) Me.lblNavLocation.TabIndex = 7 Me.lblNavLocation.Text = "No Records" Me.lblNavLocation.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'btnNavNext ' Me.btnNavNext.Location = New System.Drawing.Point(315, 109) Me.btnNavNext.Name = "btnNavNext" Me.btnNavNext.Size = New System.Drawing.Size(35, 23) Me.btnNavNext.TabIndex = 8 Me.btnNavNext.Text = ">" ' 'btnLast ' Me.btnLast.Location = New System.Drawing.Point(350, 109) Me.btnLast.Name = "btnLast" Me.btnLast.Size = New System.Drawing.Size(40, 23) Me.btnLast.TabIndex = 9 Me.btnLast.Text = ">>" ' 'btnAdd ' Me.btnAdd.Location = New System.Drawing.Point(145, 142) Me.btnAdd.Name = "btnAdd" Me.btnAdd.TabIndex = 10 Me.btnAdd.Text = "&Add" ' 'btnDelete ' Me.btnDelete.Location = New System.Drawing.Point(230, 142) Me.btnDelete.Name = "btnDelete" Me.btnDelete.TabIndex = 11 Me.btnDelete.Text = "&Delete" ' 'btnCancel ' Me.btnCancel.Location = New System.Drawing.Point(315, 142) Me.btnCancel.Name = "btnCancel" Me.btnCancel.TabIndex = 12 Me.btnCancel.Text = "&Cancel" ' 'grdBooks ' Me.grdBooks.AllowNavigation = False Me.grdBooks.DataMember = "Authors.AuthorsBooks" Me.grdBooks.DataSource = Me.objBooks Me.grdBooks.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.grdBooks.Location = New System.Drawing.Point(10, 175) Me.grdBooks.Name = "grdBooks" Me.grdBooks.Size = New System.Drawing.Size(380, 292) Me.grdBooks.TabIndex = 13 Me.grdBooks.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.objTableStylegrdBooksBooks}) ' 'objTableStylegrdBooksBooks ' Me.objTableStylegrdBooksBooks.DataGrid = Me.grdBooks Me.objTableStylegrdBooksBooks.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.objColumnStylegrdBooksID, Me.objColumnStylegrdBooksBook}) Me.objTableStylegrdBooksBooks.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.objTableStylegrdBooksBooks.MappingName = "Books" ' 'objColumnStylegrdBooksID ' Me.objColumnStylegrdBooksID.Format = "" Me.objColumnStylegrdBooksID.FormatInfo = Nothing Me.objColumnStylegrdBooksID.HeaderText = "ID" Me.objColumnStylegrdBooksID.MappingName = "ID" Me.objColumnStylegrdBooksID.Width = 75 ' 'objColumnStylegrdBooksBook ' Me.objColumnStylegrdBooksBook.Format = "" Me.objColumnStylegrdBooksBook.FormatInfo = Nothing Me.objColumnStylegrdBooksBook.HeaderText = "Book" Me.objColumnStylegrdBooksBook.MappingName = "Book" Me.objColumnStylegrdBooksBook.Width = 75 ' 'SqlConnection1 ' Me.SqlConnection1.ConnectionString = "data source=MHMD;initial catalog=SQLBooks;integrated security=SSPI;workstation id" & _ "=MHMD;packet size=4096" ' 'SqlCommand1 ' Me.SqlCommand1.CommandText = "dbo.[NewBook]" Me.SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure Me.SqlCommand1.Connection = Me.SqlConnection1 Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing)) Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AuthorID", System.Data.SqlDbType.NVarChar, 30)) Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Book", System.Data.SqlDbType.NVarChar, 30)) ' 'FrmBooks ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(400, 447) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnLoad, Me.btnUpdate, Me.btnCancelAll, Me.lblAuthor, Me.editAuthor, Me.btnNavFirst, Me.btnNavPrev, Me.lblNavLocation, Me.btnNavNext, Me.btnLast, Me.btnAdd, Me.btnDelete, Me.btnCancel, Me.grdBooks}) Me.Name = "FrmBooks" Me.Text = "FrmBooks" CType(Me.objBooks, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.grdBooks, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.BindingContext(objBooks, "Authors").CancelCurrentEdit() Me.objBooks_PositionChanged() End Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click If (Me.BindingContext(objBooks, "Authors").Count > 0) Then Me.BindingContext(objBooks, "Authors").RemoveAt(Me.BindingContext(objBooks, "Authors").Position) Me.objBooks_PositionChanged() End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try Dim BookName As String BookName = InputBox("أدخل اسم الكتاب") If BookName = "" Then Exit Sub SqlCommand1.Parameters("@Book").Value = BookName Dim Pos As Integer Pos = Me.BindingContext(objBooks, "Authors").Position SqlCommand1.Parameters("@AuthorID").Value = _ objBooks.Authors(Pos).ID() SqlConnection1.Open() SqlCommand1.ExecuteScalar() SqlConnection1.Close() Dim BookID As Integer = _ SqlCommand1.Parameters("@RETURN_VALUE").Value Dim Slct As New SqlClient.SqlCommand() Slct.Connection = SqlConnection1 Dim p As New SqlClient.SqlParameter() p.ParameterName = "@ID" p.Direction = ParameterDirection.Input p.SqlDbType = SqlDbType.Int p.Value = BookID Slct.Parameters.Add(p) Slct.CommandType = CommandType.Text Slct.CommandText = "SELECT * FROM Books WHERE ID = @ID" Dim DA As New SqlClient.SqlDataAdapter() DA.SelectCommand = Slct DA.Fill(objBooks, "Books") Catch exc As Exception MsgBox(exc.Message) End Try Me.objBooks_PositionChanged() End Sub Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Try 'Attempt to update the datasource. Me.UpdateDataSet() Catch eUpdate As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eUpdate.Message) End Try Me.objBooks_PositionChanged() End Sub Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click Try 'Attempt to load the dataset. Me.LoadDataSet() Catch eLoad As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eLoad.Message) End Try Me.objBooks_PositionChanged() End Sub Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click Me.BindingContext(objBooks, "Authors").Position = 0 Me.objBooks_PositionChanged() End Sub Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click Me.BindingContext(objBooks, "Authors").Position = (Me.objBooks.Tables("Authors").Rows.Count - 1) Me.objBooks_PositionChanged() End Sub Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click Me.BindingContext(objBooks, "Authors").Position = (Me.BindingContext(objBooks, "Authors").Position - 1) Me.objBooks_PositionChanged() End Sub Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click Me.BindingContext(objBooks, "Authors").Position = (Me.BindingContext(objBooks, "Authors").Position + 1) Me.objBooks_PositionChanged() End Sub Private Sub objBooks_PositionChanged() Me.lblNavLocation.Text = (((Me.BindingContext(objBooks, "Authors").Position + 1).ToString + " of ") _ + Me.BindingContext(objBooks, "Authors").Count.ToString) End Sub Private Sub btnCancelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelAll.Click Me.objBooks.RejectChanges() End Sub Public Sub UpdateDataSet() 'Create a new dataset to hold the changes that have been made to the main dataset. Dim objDataSetChanges As EditBooks.Books = New EditBooks.Books() 'Stop any current edits. Me.BindingContext(objBooks, "Authors").EndCurrentEdit() Me.BindingContext(objBooks, "Books").EndCurrentEdit() 'Get the changes that have been made to the main dataset. objDataSetChanges = CType(objBooks.GetChanges, EditBooks.Books) 'Check to see if any changes have been made. If (Not (objDataSetChanges) Is Nothing) Then Try 'There are changes that need to be made, so attempt to update the datasource by 'calling the update method and passing the dataset and any parameters. Me.UpdateDataSource(objDataSetChanges) objBooks.Merge(objDataSetChanges) objBooks.AcceptChanges() Catch eUpdate As System.Exception 'Add your error handling code here. Throw eUpdate End Try 'Add your code to check the returned dataset for any errors that may have been 'pushed into the row object's error. End If End Sub Public Sub LoadDataSet() 'Create a new dataset to hold the records returned from the call to FillDataSet. 'A temporary dataset is used because filling the existing dataset would 'require the databindings to be rebound. Dim objDataSetTemp As EditBooks.Books objDataSetTemp = New EditBooks.Books() Try 'Attempt to fill the temporary dataset. Me.FillDataSet(objDataSetTemp) Catch eFillDataSet As System.Exception 'Add your error handling code here. Throw eFillDataSet End Try Try 'Empty the old records from the dataset. objBooks.Clear() 'Merge the records into the main dataset. objBooks.Merge(objDataSetTemp) Catch eLoadMerge As System.Exception 'Add your error handling code here. Throw eLoadMerge End Try End Sub Public Sub UpdateDataSource(ByVal ChangedRows As EditBooks.Books) Try 'The data source only needs to be updated if there are changes pending. If (Not (ChangedRows) Is Nothing) Then 'Open the connection. Me.OleDbConnection1.Open() 'Attempt to update the data source. OleDbDataAdapter1.Update(ChangedRows) OleDbDataAdapter2.Update(ChangedRows) End If Catch updateException As System.Exception 'Add your error handling code here. Throw updateException Finally 'Close the connection whether or not the exception was thrown. Me.OleDbConnection1.Close() End Try End Sub Public Sub FillDataSet(ByVal dataSet As EditBooks.Books) 'Turn off constraint checking before the dataset is filled. 'This allows the adapters to fill the dataset without concern 'for dependencies between the tables. dataSet.EnforceConstraints = False Try 'Open the connection. Me.OleDbConnection1.Open() 'Attempt to fill the dataset through the OleDbDataAdapter1. Me.OleDbDataAdapter1.Fill(dataSet) Me.OleDbDataAdapter2.Fill(dataSet) Catch fillException As System.Exception 'Add your error handling code here. Throw fillException Finally 'Turn constraint checking back on. dataSet.EnforceConstraints = True 'Close the connection whether or not the exception was thrown. Me.OleDbConnection1.Close() End Try End Sub End Class