📄 form1.cs
字号:
this.oleDbDataAdapter2.UpdateCommand = this.oleDbUpdateCommand2;
//
// oleDbDeleteCommand2
//
this.oleDbDeleteCommand2.CommandText = "DELETE FROM titles WHERE (title_id = ?) AND (price = ? OR ? IS NULL AND price IS " +
"NULL) AND (pub_id = ? OR ? IS NULL AND pub_id IS NULL) AND (title = ?)";
this.oleDbDeleteCommand2.Connection = this.oleDbConnection1;
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_title_id", System.Data.OleDb.OleDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "title_id", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_price", System.Data.OleDb.OleDbType.Currency, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_price1", System.Data.OleDb.OleDbType.Currency, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_pub_id", System.Data.OleDb.OleDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pub_id", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_pub_id1", System.Data.OleDb.OleDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pub_id", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_title", System.Data.OleDb.OleDbType.VarChar, 80, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "title", System.Data.DataRowVersion.Original, null));
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO titles(title_id, title, pub_id, price) VALUES (?, ?, ?, ?); SELECT ti" +
"tle_id, title, pub_id, price FROM titles WHERE (title_id = ?)";
this.oleDbInsertCommand2.Connection = this.oleDbConnection1;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("title_id", System.Data.OleDb.OleDbType.VarChar, 6, "title_id"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("title", System.Data.OleDb.OleDbType.VarChar, 80, "title"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("pub_id", System.Data.OleDb.OleDbType.VarChar, 4, "pub_id"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("price", System.Data.OleDb.OleDbType.Currency, 8, "price"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Select_title_id", System.Data.OleDb.OleDbType.VarChar, 6, "title_id"));
//
// oleDbSelectCommand2
//
this.oleDbSelectCommand2.CommandText = "SELECT title_id, title, pub_id, price FROM titles";
this.oleDbSelectCommand2.Connection = this.oleDbConnection1;
//
// oleDbUpdateCommand2
//
this.oleDbUpdateCommand2.CommandText = @"UPDATE titles SET title_id = ?, title = ?, pub_id = ?, price = ? WHERE (title_id = ?) AND (price = ? OR ? IS NULL AND price IS NULL) AND (pub_id = ? OR ? IS NULL AND pub_id IS NULL) AND (title = ?); SELECT title_id, title, pub_id, price FROM titles WHERE (title_id = ?)";
this.oleDbUpdateCommand2.Connection = this.oleDbConnection1;
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("title_id", System.Data.OleDb.OleDbType.VarChar, 6, "title_id"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("title", System.Data.OleDb.OleDbType.VarChar, 80, "title"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("pub_id", System.Data.OleDb.OleDbType.VarChar, 4, "pub_id"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("price", System.Data.OleDb.OleDbType.Currency, 8, "price"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_title_id", System.Data.OleDb.OleDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "title_id", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_price", System.Data.OleDb.OleDbType.Currency, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_price1", System.Data.OleDb.OleDbType.Currency, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_pub_id", System.Data.OleDb.OleDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pub_id", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_pub_id1", System.Data.OleDb.OleDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pub_id", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_title", System.Data.OleDb.OleDbType.VarChar, 80, 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("Select_title_id", System.Data.OleDb.OleDbType.VarChar, 6, "title_id"));
//
// dsPublishersTitles1
//
this.dsPublishersTitles1.DataSetName = "dsPublishersTitles";
this.dsPublishersTitles1.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dsPublishersTitles1.Namespace = "http://www.tempuri.org/dsPublishersTitles.xsd";
//
// dataGrid1
//
this.dataGrid1.DataMember = "publishers.publisherstitles";
this.dataGrid1.DataSource = this.dsPublishersTitles1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 104);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(352, 152);
this.dataGrid1.TabIndex = 0;
//
// dataGrid2
//
this.dataGrid2.DataMember = "publishers";
this.dataGrid2.DataSource = this.dsPublishersTitles1;
this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid2.Location = new System.Drawing.Point(16, 8);
this.dataGrid2.Name = "dataGrid2";
this.dataGrid2.Size = new System.Drawing.Size(352, 88);
this.dataGrid2.TabIndex = 1;
//
// btnUp
//
this.btnUp.Dock = System.Windows.Forms.DockStyle.Bottom;
this.btnUp.Location = new System.Drawing.Point(0, 270);
this.btnUp.Name = "btnUp";
this.btnUp.Size = new System.Drawing.Size(376, 23);
this.btnUp.TabIndex = 2;
this.btnUp.Text = "更新数据库";
this.btnUp.Click += new System.EventHandler(this.btnUp_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnUp,
this.dataGrid2,
this.dataGrid1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dsPublishersTitles1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnUp_Click(object sender, System.EventArgs e)
{
//设置ds1只包含子表中删除的记录
DataTable ds1;
ds1= dsPublishersTitles1.titles.GetChanges(DataRowState.Deleted);
//设置ds2只包含子表中添加的记录
DataTable ds2;
ds2=dsPublishersTitles1.titles.GetChanges(DataRowState.Added);
//设置ds3只包含子表中被修改的记录
DataTable ds3;
ds3=dsPublishersTitles1.titles.GetChanges(DataRowState.Modified);
try
{
oleDbDataAdapter2.Update(ds1);
oleDbDataAdapter1.Update(dsPublishersTitles1, "publisher");
oleDbDataAdapter2.Update(ds2);
oleDbDataAdapter2.Update(ds3);
dsPublishersTitles1.AcceptChanges();
ds1.Dispose();
ds2.Dispose();
ds3.Dispose();
}
catch {}
}
private void Form1_Load(object sender, System.EventArgs e)
{
dsPublishersTitles1.Clear();
oleDbDataAdapter1.Fill(dsPublishersTitles1);
oleDbDataAdapter2.Fill(dsPublishersTitles1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -