databasexmlwriter.cs
来自「this is a good book for the visual c#」· CS 代码 · 共 284 行 · 第 1/2 页
CS
284 行
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_firstName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "firstName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
//
// playersDataSet
//
this.playersDataSet.DataSetName = "NewDataSet";
this.playersDataSet.Locale = new System.Globalization.CultureInfo("en-US");
//
// playersDataGrid
//
this.playersDataGrid.DataMember = "";
this.playersDataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.playersDataGrid.Location = new System.Drawing.Point(8, 40);
this.playersDataGrid.Name = "playersDataGrid";
this.playersDataGrid.Size = new System.Drawing.Size(312, 168);
this.playersDataGrid.TabIndex = 0;
//
// writeButton
//
this.writeButton.Location = new System.Drawing.Point(60, 8);
this.writeButton.Name = "writeButton";
this.writeButton.Size = new System.Drawing.Size(208, 24);
this.writeButton.TabIndex = 1;
this.writeButton.Text = "Write to XML";
this.writeButton.Click += new System.EventHandler(this.writeButton_Click);
//
// outputTextBox
//
this.outputTextBox.BackColor = System.Drawing.SystemColors.Window;
this.outputTextBox.Location = new System.Drawing.Point(8, 216);
this.outputTextBox.Multiline = true;
this.outputTextBox.Name = "outputTextBox";
this.outputTextBox.ReadOnly = true;
this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.outputTextBox.Size = new System.Drawing.Size(312, 96);
this.outputTextBox.TabIndex = 2;
this.outputTextBox.Text = "";
//
// oleDbSelectCommand2
//
this.oleDbSelectCommand2.CommandText = "SELECT firstName, lastName, battingAverage, playerID FROM Players";
this.oleDbSelectCommand2.Connection = this.baseballConnection;
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO Players(firstName, lastName, battingAverage) VALUES (?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.baseballConnection;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("firstName", System.Data.OleDb.OleDbType.VarWChar, 50, "firstName"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("lastName", System.Data.OleDb.OleDbType.VarWChar, 50, "lastName"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("battingAverage", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Current, null));
//
// oleDbUpdateCommand2
//
this.oleDbUpdateCommand2.CommandText = @"UPDATE Players SET firstName = ?, lastName = ?, battingAverage = ? WHERE (playerID = ?) AND (battingAverage = ? OR ? IS NULL AND battingAverage IS NULL) AND (firstName = ? OR ? IS NULL AND firstName IS NULL) AND (lastName = ? OR ? IS NULL AND lastName IS NULL)";
this.oleDbUpdateCommand2.Connection = this.baseballConnection;
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("firstName", System.Data.OleDb.OleDbType.VarWChar, 50, "firstName"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("lastName", System.Data.OleDb.OleDbType.VarWChar, 50, "lastName"));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("battingAverage", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Current, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_playerID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "playerID", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_battingAverage", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_battingAverage1", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_firstName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "firstName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_firstName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "firstName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
//
// oleDbDeleteCommand2
//
this.oleDbDeleteCommand2.CommandText = "DELETE FROM Players WHERE (playerID = ?) AND (battingAverage = ? OR ? IS NULL AND" +
" battingAverage IS NULL) AND (firstName = ? OR ? IS NULL AND firstName IS NULL) " +
"AND (lastName = ? OR ? IS NULL AND lastName IS NULL)";
this.oleDbDeleteCommand2.Connection = this.baseballConnection;
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_playerID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "playerID", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_battingAverage", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_battingAverage1", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(15)), ((System.Byte)(0)), "battingAverage", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_firstName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "firstName", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_firstName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "firstName", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_lastName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "lastName", System.Data.DataRowVersion.Original, null));
//
// baseballConnection
//
this.baseballConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\books\2001\csphtp1\csphtp1_examples\ch19\Fig19_30\XMLWriter\Baseball.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";
//
// XMLWriter
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 325);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.outputTextBox,
this.writeButton,
this.playersDataGrid});
this.Name = "XMLWriter";
this.Text = "XMLWriter";
((System.ComponentModel.ISupportInitialize)(this.playersDataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.playersDataGrid)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new DatabaseXMLWriter());
}
// write XML representation of DataSet when button clicked
private void writeButton_Click(object sender, System.EventArgs e)
{
// write XML representation of DataSet to file
playersDataSet.WriteXml( "Players.xml" );
// display XML in TextBox
outputTextBox.Text += "Writing the following XML:\n\n" +
playersDataSet.GetXml() + "\n\n";
}
}
}
/*
**************************************************************************
* (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall. *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?