using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace DataBooksCombo
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.OleDb.OleDbConnection conRnR;
private System.Data.OleDb.OleDbDataAdapter daBooks;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand2;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand2;
private System.Data.OleDb.OleDbCommand oleDbUpdateCommand2;
private System.Data.OleDb.OleDbCommand oleDbDeleteCommand2;
private System.Data.OleDb.OleDbDataAdapter daTitles;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private DataBooksCombo.dsBooks dsBooks1;
private DataBooksCombo.dsTitles1 dsTitles1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox titlesComboBox;
private System.Windows.Forms.Label IsbnLabel;
private System.Windows.Forms.Label authorLabel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.conRnR = new System.Data.OleDb.OleDbConnection();
this.daBooks = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand2 = new System.Data.OleDb.OleDbCommand();
this.daTitles = new System.Data.OleDb.OleDbDataAdapter();
this.dsBooks1 = new DataBooksCombo.dsBooks();
this.dsTitles1 = new DataBooksCombo.dsTitles1();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.titlesComboBox = new System.Windows.Forms.ComboBox();
this.IsbnLabel = new System.Windows.Forms.Label();
this.authorLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dsBooks1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dsTitles1)).BeginInit();
this.SuspendLayout();
//
// conRnR
//
this.conRnR.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\360\Programs_managedVCSharp\rnrbooks.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
//
// daBooks
//
this.daBooks.DeleteCommand = this.oleDbDeleteCommand1;
this.daBooks.InsertCommand = this.oleDbInsertCommand1;
this.daBooks.SelectCommand = this.oleDbSelectCommand1;
this.daBooks.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Books", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ISBN", "ISBN"),
new System.Data.Common.DataColumnMapping("Title", "Title"),
new System.Data.Common.DataColumnMapping("Author", "Author")})});
this.daBooks.UpdateCommand = this.oleDbUpdateCommand1;
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = "DELETE FROM Books WHERE (ISBN = ?) AND (Author = ? OR ? IS NULL AND Author IS NUL" +
"L) AND (Title = ? OR ? IS NULL AND Title IS NULL)";
this.oleDbDeleteCommand1.Connection = this.conRnR;
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = "INSERT INTO Books(ISBN, Title, Author) VALUES (?, ?, ?)";
this.oleDbInsertCommand1.Connection = this.conRnR;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarWChar, 30, "Author"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT ISBN, Title, Author FROM Books WHERE (Title = ?)";
this.oleDbSelectCommand1.Connection = this.conRnR;
this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = "UPDATE Books SET ISBN = ?, Title = ?, Author = ? WHERE (ISBN = ?) AND (Author = ?" +
" OR ? IS NULL AND Author IS NULL) AND (Title = ? OR ? IS NULL AND Title IS NULL)" +
"";
this.oleDbUpdateCommand1.Connection = this.conRnR;
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarWChar, 30, "Author"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// oleDbSelectCommand2
//
this.oleDbSelectCommand2.CommandText = "SELECT Title, ISBN FROM Books";
this.oleDbSelectCommand2.Connection = this.conRnR;
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO Books(Title, ISBN) VALUES (?, ?)";
this.oleDbInsertCommand2.Connection = this.conRnR;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
//
// oleDbUpdateCommand2
//
this.oleDbUpdateCommand2.CommandText = "UPDATE Books SET Title = ?, ISBN = ? WHERE (ISBN = ?) AND (Title = ? OR ? IS NULL" +
" AND Title IS NULL)";
this.oleDbUpdateCommand2.Connection = this.conRnR;
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// oleDbDeleteCommand2
//
this.oleDbDeleteCommand2.CommandText = "DELETE FROM Books WHERE (ISBN = ?) AND (Title = ? OR ? IS NULL AND Title IS NULL)" +
"";
this.oleDbDeleteCommand2.Connection = this.conRnR;
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// daTitles
//
this.daTitles.DeleteCommand = this.oleDbDeleteCommand2;
this.daTitles.InsertCommand = this.oleDbInsertCommand2;
this.daTitles.SelectCommand = this.oleDbSelectCommand2;
this.daTitles.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Books", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Title", "Title"),
new System.Data.Common.DataColumnMapping("ISBN", "ISBN")})});
this.daTitles.UpdateCommand = this.oleDbUpdateCommand2;
//
// dsBooks1
//
this.dsBooks1.DataSetName = "dsBooks";
this.dsBooks1.Locale = new System.Globalization.CultureInfo("en-US");
this.dsBooks1.Namespace = "http://www.tempuri.org/dsBooks.xsd";
//
// dsTitles1
//
this.dsTitles1.DataSetName = "dsTitles1";
this.dsTitles1.Locale = new System.Globalization.CultureInfo("en-US");
this.dsTitles1.Namespace = "http://www.tempuri.org/dsTitles1.xsd";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Select Title";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 96);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 1;
this.label2.Text = "ISBN";
//
// label3
//
this.label3.Location = new System.Drawing.Point(48, 152);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 2;
this.label3.Text = "Author";
//
// titlesComboBox
//
this.titlesComboBox.DataSource = this.dsTitles1.Books;
this.titlesComboBox.DisplayMember = "Title";
this.titlesComboBox.Location = new System.Drawing.Point(136, 40);
this.titlesComboBox.Name = "titlesComboBox";
this.titlesComboBox.Size = new System.Drawing.Size(288, 21);
this.titlesComboBox.TabIndex = 3;
this.titlesComboBox.SelectedIndexChanged += new System.EventHandler(this.titlesComboBox_SelectedIndexChanged);
//
// IsbnLabel
//
this.IsbnLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.IsbnLabel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsBooks1, "Books.ISBN"));
this.IsbnLabel.Location = new System.Drawing.Point(136, 96);
this.IsbnLabel.Name = "IsbnLabel";
this.IsbnLabel.Size = new System.Drawing.Size(184, 23);
this.IsbnLabel.TabIndex = 4;
//
// authorLabel
//
this.authorLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.authorLabel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsBooks1, "Books.Author"));
this.authorLabel.Location = new System.Drawing.Point(128, 136);
this.authorLabel.Name = "authorLabel";
this.authorLabel.Size = new System.Drawing.Size(192, 23);
this.authorLabel.TabIndex = 5;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.authorLabel,
this.IsbnLabel,
this.titlesComboBox,
this.label3,
this.label2,
this.label1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dsBooks1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dsTitles1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
daTitles.Fill(dsTitles1);
titlesComboBox.SelectedIndex = -1;
}

private void titlesComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (titlesComboBox.SelectedIndex != -1)
{
dsBooks1.Clear();
daBooks.SelectCommand.Parameters["Title"].Value = titlesComboBox.Text;
daBooks.Fill(dsBooks1);
if (dsBooks1.Tables["Books"].Rows.Count == 0)
MessageBox.Show("Title not found.");
}
}
}
}