Is this what youre after?
----------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication3
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Data.OleDb.OleDbDataAdapter agencyAdapter;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
private System.Data.OleDb.OleDbDataAdapter predecessorAdapter;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand2;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand2;
private WindowsApplication3.DataSet1 dataSet;
private System.Data.OleDb.OleDbCommand oleDbCommand1;
private System.Data.OleDb.OleDbCommand oleDbCommand2;
private System.Data.OleDb.OleDbCommand oleDbCommand3;
private System.Windows.Forms.Button button2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
agencyAdapter.Fill(dataSet);
predecessorAdapter.Fill(dataSet);
//
// 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.button1 = new System.Windows.Forms.Button();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.agencyAdapter = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.dataSet = new WindowsApplication3.DataSet1();
this.predecessorAdapter = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbInsertCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbCommand2 = new System.Data.OleDb.OleDbCommand();
this.oleDbCommand3 = new System.Data.OleDb.OleDbCommand();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d ataSet)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 224);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data Source=""C:\Program
Files\SoftLaw\Databases\AgencyDatabase.mdb"";Passw ord=;Jet OLEDB:Engine
Type=5;Jet OLEDB:Global Bulk
Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0" ";Jet OLEDB:System
database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet
OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False";
//
// agencyAdapter
//
this.agencyAdapter.InsertCommand = this.oleDbInsertCommand1;
this.agencyAdapter.SelectCommand = this.oleDbSelectCommand1;
this.agencyAdapter.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Agency",
new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("budgetStatus ", "budgetStatus"),
new
System.Data.Common.DataColumnMapping("cessationDat e", "cessationDate"),
new
System.Data.Common.DataColumnMapping("cessationDat eSource",
"cessationDateSource"),
new
System.Data.Common.DataColumnMapping("cessationIns trument",
"cessationInstrument"),
new
System.Data.Common.DataColumnMapping("comments", "comments"),
new
System.Data.Common.DataColumnMapping("creationDate ", "creationDate"),
new
System.Data.Common.DataColumnMapping("creationDate Source",
"creationDateSource"),
new
System.Data.Common.DataColumnMapping("creationInst rument",
"creationInstrument"),
new
System.Data.Common.DataColumnMapping("CurrentAgenc y", "CurrentAgency"),
new
System.Data.Common.DataColumnMapping("id", "id"),
new
System.Data.Common.DataColumnMapping("name", "name"),
new
System.Data.Common.DataColumnMapping("reasonForNon Recognition",
"reasonForNonRecognition"),
new
System.Data.Common.DataColumnMapping("scheduleType ", "scheduleType"),
new
System.Data.Common.DataColumnMapping("ScheduleType Source",
"ScheduleTypeSource"),
new
System.Data.Common.DataColumnMapping("state", "state"),
new
System.Data.Common.DataColumnMapping("statusChange ", "statusChange"),
new
System.Data.Common.DataColumnMapping("UniqueID", "UniqueID")})});
this.agencyAdapter.UpdateCommand = this.oleDbCommand3;
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = @"INSERT INTO
Agency(budgetStatus, cessationDate, cessationDateSource,
cessationInstrument, comments, creationDate, creationDateSource,
creationInstrument, CurrentAgency, id, name, reasonForNonRecognition,
scheduleType, ScheduleTypeSource, state, statusChange, UniqueID) VALUES (?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("budgetStatus",
System.Data.OleDb.OleDbType.Integer, 0, "budgetStatus"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationDate",
System.Data.OleDb.OleDbType.DBDate, 0, "cessationDate"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationDateSou rce",
System.Data.OleDb.OleDbType.VarWChar, 255, "cessationDateSource"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationInstrum ent",
System.Data.OleDb.OleDbType.VarWChar, 255, "cessationInstrument"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("comments",
System.Data.OleDb.OleDbType.VarWChar, 0, "comments"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationDate",
System.Data.OleDb.OleDbType.DBDate, 0, "creationDate"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationDateSour ce",
System.Data.OleDb.OleDbType.VarWChar, 255, "creationDateSource"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationInstrume nt",
System.Data.OleDb.OleDbType.VarWChar, 255, "creationInstrument"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CurrentAgency",
System.Data.OleDb.OleDbType.VarWChar, 50, "CurrentAgency"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("id", System.Data.OleDb.OleDbType.Integer,
0, "id"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 255, "name"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("reasonForNonReco gnition",
System.Data.OleDb.OleDbType.VarWChar, 0, "reasonForNonRecognition"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("scheduleType",
System.Data.OleDb.OleDbType.Integer, 0, "scheduleType"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ScheduleTypeSour ce",
System.Data.OleDb.OleDbType.VarWChar, 255, "ScheduleTypeSource"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("state",
System.Data.OleDb.OleDbType.Integer, 0, "state"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("statusChange",
System.Data.OleDb.OleDbType.VarWChar, 5, "statusChange"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("UniqueID",
System.Data.OleDb.OleDbType.SmallInt, 0, "UniqueID"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = @"SELECT budgetStatus,
cessationDate, cessationDateSource, cessationInstrument, comments,
creationDate, creationDateSource, creationInstrument, CurrentAgency, id,
name, reasonForNonRecognition, scheduleType, ScheduleTypeSource, state,
statusChange, UniqueID FROM Agency";
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
//
// dataSet
//
this.dataSet.DataSetName = "DataSet1";
this.dataSet.Locale = new System.Globalization.CultureInfo("en-AU");
//
// predecessorAdapter
//
this.predecessorAdapter.DeleteCommand = this.oleDbCommand2;
this.predecessorAdapter.InsertCommand = this.oleDbInsertCommand2;
this.predecessorAdapter.SelectCommand = this.oleDbSelectCommand2;
this.predecessorAdapter.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"Predecessor", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("comments", "comments"),
new
System.Data.Common.DataColumnMapping("predecessor" , "predecessor"),
new
System.Data.Common.DataColumnMapping("successor", "successor")})});
this.predecessorAdapter.UpdateCommand = this.oleDbCommand1;
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO
Predecessor(comments, predecessor, successor) VALUES (?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.oleDbConnection1;
this.oleDbInsertCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("comments",
System.Data.OleDb.OleDbType.VarWChar, 0, "comments"));
this.oleDbInsertCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("predecessor",
System.Data.OleDb.OleDbType.Integer, 0, "predecessor"));
this.oleDbInsertCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("successor",
System.Data.OleDb.OleDbType.Integer, 0, "successor"));
//
// oleDbSelectCommand2
//
this.oleDbSelectCommand2.CommandText = "SELECT comments, predecessor,
successor FROM Predecessor";
this.oleDbSelectCommand2.Connection = this.oleDbConnection1;
//
// oleDbCommand1
//
this.oleDbCommand1.CommandText = "UPDATE Predecessor SET comments = ?,
predecessor = ?, successor = ? WHERE (predec" +
"essor = ?) AND (successor = ?)";
this.oleDbCommand1.Connection = this.oleDbConnection1;
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("comments",
System.Data.OleDb.OleDbType.VarWChar, 0, "comments"));
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("predecessor",
System.Data.OleDb.OleDbType.Integer, 0, "predecessor"));
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("successor",
System.Data.OleDb.OleDbType.Integer, 0, "successor"));
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_predece ssor",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "predecessor", System.Data.DataRowVersion.Original,
null));
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_success or",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "successor", System.Data.DataRowVersion.Original,
null));
//
// oleDbCommand2
//
this.oleDbCommand2.CommandText = "DELETE FROM Predecessor WHERE
(predecessor = ? AND successor = ?)";
this.oleDbCommand2.Connection = this.oleDbConnection1;
this.oleDbCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("predecessor",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "predecessor", System.Data.DataRowVersion.Original,
null));
this.oleDbCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("successor",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "successor", System.Data.DataRowVersion.Original,
null));
//
// oleDbCommand3
//
this.oleDbCommand3.CommandText = @"UPDATE Agency SET budgetStatus = ?,
cessationDate = ?, cessationInstrument = ?, cessationDateSource = ?,
comments = ?, creationDate = ?, creationDateSource = ?, creationInstrument =
?, name = ?, reasonForNonRecognition = ?, scheduleType = ?,
ScheduleTypeSource = ?, state = ?, statusChange = ? WHERE (id = ?)";
this.oleDbCommand3.Connection = this.oleDbConnection1;
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("budgetStatus",
System.Data.OleDb.OleDbType.Integer, 0, "budgetStatus"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationDate",
System.Data.OleDb.OleDbType.DBDate, 0, "cessationDate"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationInstrum ent",
System.Data.OleDb.OleDbType.VarWChar, 255, "cessationInstrument"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("cessationDateSou rce",
System.Data.OleDb.OleDbType.VarWChar, 255, "cessationDateSource"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("comments",
System.Data.OleDb.OleDbType.VarWChar, 0, "comments"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationDate",
System.Data.OleDb.OleDbType.DBDate, 0, "creationDate"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationDateSour ce",
System.Data.OleDb.OleDbType.VarWChar, 255, "creationDateSource"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("creationInstrume nt",
System.Data.OleDb.OleDbType.VarWChar, 255, "creationInstrument"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 255, "name"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("reasonForNonReco gnition",
System.Data.OleDb.OleDbType.VarWChar, 0, "reasonForNonRecognition"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("scheduleType",
System.Data.OleDb.OleDbType.Integer, 0, "scheduleType"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ScheduleTypeSour ce",
System.Data.OleDb.OleDbType.VarWChar, 255, "ScheduleTypeSource"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("state",
System.Data.OleDb.OleDbType.Integer, 0, "state"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("statusChange",
System.Data.OleDb.OleDbType.VarWChar, 5, "statusChange"));
this.oleDbCommand3.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
//
// button2
//
this.button2.Location = new System.Drawing.Point(200, 232);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.d ataSet)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
int counthis = dataSet.Predecessor.Rows.Count;
DataSet1.PredecessorRow rowtodelete = (DataSet1.PredecessorRow)
dataSet.Predecessor.Select("successor=" + 2 + " AND predecessor=" + 1)[0];
dataSet.Predecessor.RemovePredecessorRow(rowtodele te);
int counthis2 = dataSet.Predecessor.Rows.Count;
MessageBox.Show("sdsdfsdfs");
updatethisShit();
}
private void button2_Click(object sender, System.EventArgs e)
{
DataSet1.PredecessorRow rowtoadd =
dataSet.Predecessor.NewPredecessorRow();
rowtoadd.predecessor = 1;
rowtoadd.successor = 2;
dataSet.Predecessor.Rows.Add(rowtoadd);
MessageBox.Show("sdsdfsdfs");
updatethisShit();
}
private void updatethisShit()
{
predecessorAdapter.Update(dataSet);
}
}
}
----------------------------------------------------
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Grant <gp*****@hotmail.com> wrote:
<snip>
Heres the code:
<snip>
That's not the code. That's a couple of snippets of code. In
particular, it's nothing I can compile and run.
Please read http://www.pobox.com/~skeet/csharp/complete.html again
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too