Is this what youre after?
----------------------------------------------------
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace WindowsApplicat ion3
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
private System.Data.Ole Db.OleDbConnect ion oleDbConnection 1;
private System.Data.Ole Db.OleDbDataAda pter agencyAdapter;
private System.Data.Ole Db.OleDbCommand oleDbSelectComm and1;
private System.Data.Ole Db.OleDbCommand oleDbInsertComm and1;
private System.Data.Ole Db.OleDbDataAda pter predecessorAdap ter;
private System.Data.Ole Db.OleDbCommand oleDbSelectComm and2;
private System.Data.Ole Db.OleDbCommand oleDbInsertComm and2;
private WindowsApplicat ion3.DataSet1 dataSet;
private System.Data.Ole Db.OleDbCommand oleDbCommand1;
private System.Data.Ole Db.OleDbCommand oleDbCommand2;
private System.Data.Ole Db.OleDbCommand oleDbCommand3;
private System.Windows. Forms.Button button2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
agencyAdapter.F ill(dataSet);
predecessorAdap ter.Fill(dataSe t);
//
// TODO: Add any constructor code after InitializeCompo nent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this.oleDbConne ction1 = new System.Data.Ole Db.OleDbConnect ion();
this.agencyAdap ter = new System.Data.Ole Db.OleDbDataAda pter();
this.oleDbInser tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbSelec tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.dataSet = new WindowsApplicat ion3.DataSet1() ;
this.predecesso rAdapter = new System.Data.Ole Db.OleDbDataAda pter();
this.oleDbInser tCommand2 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbSelec tCommand2 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbComma nd1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbComma nd2 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbComma nd3 = new System.Data.Ole Db.OleDbCommand ();
this.button2 = new System.Windows. Forms.Button();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet)).B eginInit();
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(64, 224);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// oleDbConnection 1
//
this.oleDbConne ction1.Connecti onString = @"Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data Source=""C:\Pro gram
Files\SoftLaw\D atabases\Agency Database.mdb""; Password=;Jet OLEDB:Engine
Type=5;Jet OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Jet.OLEDB .4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False ;Extended Properties=;Mod e=Share Deny None;Jet
OLEDB:New Database Password=;Jet OLEDB:Create System Database=False; Jet
OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact Without Replica
Repair=False;Us er ID=Admin;Jet OLEDB:Encrypt Database=False" ;
//
// agencyAdapter
//
this.agencyAdap ter.InsertComma nd = this.oleDbInser tCommand1;
this.agencyAdap ter.SelectComma nd = this.oleDbSelec tCommand1;
this.agencyAdap ter.TableMappin gs.AddRange(new
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "Agency",
new System.Data.Com mon.DataColumnM apping[] {
new
System.Data.Com mon.DataColumnM apping("budgetS tatus", "budgetStatus") ,
new
System.Data.Com mon.DataColumnM apping("cessati onDate", "cessationDate" ),
new
System.Data.Com mon.DataColumnM apping("cessati onDateSource",
"cessationDateS ource"),
new
System.Data.Com mon.DataColumnM apping("cessati onInstrument",
"cessationInstr ument"),
new
System.Data.Com mon.DataColumnM apping("comment s", "comments") ,
new
System.Data.Com mon.DataColumnM apping("creatio nDate", "creationDate") ,
new
System.Data.Com mon.DataColumnM apping("creatio nDateSource",
"creationDateSo urce"),
new
System.Data.Com mon.DataColumnM apping("creatio nInstrument",
"creationInstru ment"),
new
System.Data.Com mon.DataColumnM apping("Current Agency", "CurrentAgency" ),
new
System.Data.Com mon.DataColumnM apping("id", "id"),
new
System.Data.Com mon.DataColumnM apping("name", "name"),
new
System.Data.Com mon.DataColumnM apping("reasonF orNonRecognitio n",
"reasonForNonRe cognition"),
new
System.Data.Com mon.DataColumnM apping("schedul eType", "scheduleType") ,
new
System.Data.Com mon.DataColumnM apping("Schedul eTypeSource",
"ScheduleTypeSo urce"),
new
System.Data.Com mon.DataColumnM apping("state", "state"),
new
System.Data.Com mon.DataColumnM apping("statusC hange", "statusChange") ,
new
System.Data.Com mon.DataColumnM apping("UniqueI D", "UniqueID")})}) ;
this.agencyAdap ter.UpdateComma nd = this.oleDbComma nd3;
//
// oleDbInsertComm and1
//
this.oleDbInser tCommand1.Comma ndText = @"INSERT INTO
Agency(budgetSt atus, cessationDate, cessationDateSo urce,
cessationInstru ment, comments, creationDate, creationDateSou rce,
creationInstrum ent, CurrentAgency, id, name, reasonForNonRec ognition,
scheduleType, ScheduleTypeSou rce, state, statusChange, UniqueID) VALUES (?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
this.oleDbInser tCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("budgetStatu s",
System.Data.Ole Db.OleDbType.In teger, 0, "budgetStatus") );
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("cessationDa te",
System.Data.Ole Db.OleDbType.DB Date, 0, "cessationDate" ));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("cessationDa teSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "cessationDateS ource"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("cessationIn strument",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "cessationInstr ument"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("comments",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "comments") );
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("creationDat e",
System.Data.Ole Db.OleDbType.DB Date, 0, "creationDate") );
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("creationDat eSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "creationDateSo urce"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("creationIns trument",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "creationInstru ment"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CurrentAgen cy",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "CurrentAgency" ));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("id", System.Data.Ole Db.OleDbType.In teger,
0, "id"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("name",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "name"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("reasonForNo nRecognition",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "reasonForNonRe cognition"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("scheduleTyp e",
System.Data.Ole Db.OleDbType.In teger, 0, "scheduleType") );
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("ScheduleTyp eSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "ScheduleTypeSo urce"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("state",
System.Data.Ole Db.OleDbType.In teger, 0, "state"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("statusChang e",
System.Data.Ole Db.OleDbType.Va rWChar, 5, "statusChange") );
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("UniqueID",
System.Data.Ole Db.OleDbType.Sm allInt, 0, "UniqueID") );
//
// oleDbSelectComm and1
//
this.oleDbSelec tCommand1.Comma ndText = @"SELECT budgetStatus,
cessationDate, cessationDateSo urce, cessationInstru ment, comments,
creationDate, creationDateSou rce, creationInstrum ent, CurrentAgency, id,
name, reasonForNonRec ognition, scheduleType, ScheduleTypeSou rce, state,
statusChange, UniqueID FROM Agency";
this.oleDbSelec tCommand1.Conne ction = this.oleDbConne ction1;
//
// dataSet
//
this.dataSet.Da taSetName = "DataSet1";
this.dataSet.Lo cale = new System.Globaliz ation.CultureIn fo("en-AU");
//
// predecessorAdap ter
//
this.predecesso rAdapter.Delete Command = this.oleDbComma nd2;
this.predecesso rAdapter.Insert Command = this.oleDbInser tCommand2;
this.predecesso rAdapter.Select Command = this.oleDbSelec tCommand2;
this.predecesso rAdapter.TableM appings.AddRang e(new
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table",
"Predecesso r", new System.Data.Com mon.DataColumnM apping[] {
new
System.Data.Com mon.DataColumnM apping("comment s", "comments") ,
new
System.Data.Com mon.DataColumnM apping("predece ssor", "predecesso r"),
new
System.Data.Com mon.DataColumnM apping("success or", "successor")})} );
this.predecesso rAdapter.Update Command = this.oleDbComma nd1;
//
// oleDbInsertComm and2
//
this.oleDbInser tCommand2.Comma ndText = "INSERT INTO
Predecessor(com ments, predecessor, successor) VALUES (?, ?, ?)";
this.oleDbInser tCommand2.Conne ction = this.oleDbConne ction1;
this.oleDbInser tCommand2.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("comments",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "comments") );
this.oleDbInser tCommand2.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("predecessor ",
System.Data.Ole Db.OleDbType.In teger, 0, "predecessor")) ;
this.oleDbInser tCommand2.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("successor" ,
System.Data.Ole Db.OleDbType.In teger, 0, "successor" ));
//
// oleDbSelectComm and2
//
this.oleDbSelec tCommand2.Comma ndText = "SELECT comments, predecessor,
successor FROM Predecessor";
this.oleDbSelec tCommand2.Conne ction = this.oleDbConne ction1;
//
// oleDbCommand1
//
this.oleDbComma nd1.CommandText = "UPDATE Predecessor SET comments = ?,
predecessor = ?, successor = ? WHERE (predec" +
"essor = ?) AND (successor = ?)";
this.oleDbComma nd1.Connection = this.oleDbConne ction1;
this.oleDbComma nd1.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("comments",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "comments") );
this.oleDbComma nd1.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("predecessor ",
System.Data.Ole Db.OleDbType.In teger, 0, "predecessor")) ;
this.oleDbComma nd1.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("successor" ,
System.Data.Ole Db.OleDbType.In teger, 0, "successor" ));
this.oleDbComma nd1.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("Original_pr edecessor",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "predecesso r", System.Data.Dat aRowVersion.Ori ginal,
null));
this.oleDbComma nd1.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("Original_su ccessor",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "successor" , System.Data.Dat aRowVersion.Ori ginal,
null));
//
// oleDbCommand2
//
this.oleDbComma nd2.CommandText = "DELETE FROM Predecessor WHERE
(predecessor = ? AND successor = ?)";
this.oleDbComma nd2.Connection = this.oleDbConne ction1;
this.oleDbComma nd2.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("predecessor ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "predecesso r", System.Data.Dat aRowVersion.Ori ginal,
null));
this.oleDbComma nd2.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("successor" ,
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "successor" , System.Data.Dat aRowVersion.Ori ginal,
null));
//
// oleDbCommand3
//
this.oleDbComma nd3.CommandText = @"UPDATE Agency SET budgetStatus = ?,
cessationDate = ?, cessationInstru ment = ?, cessationDateSo urce = ?,
comments = ?, creationDate = ?, creationDateSou rce = ?, creationInstrum ent =
?, name = ?, reasonForNonRec ognition = ?, scheduleType = ?,
ScheduleTypeSou rce = ?, state = ?, statusChange = ? WHERE (id = ?)";
this.oleDbComma nd3.Connection = this.oleDbConne ction1;
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("budgetStatu s",
System.Data.Ole Db.OleDbType.In teger, 0, "budgetStatus") );
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("cessationDa te",
System.Data.Ole Db.OleDbType.DB Date, 0, "cessationDate" ));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("cessationIn strument",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "cessationInstr ument"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("cessationDa teSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "cessationDateS ource"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("comments",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "comments") );
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("creationDat e",
System.Data.Ole Db.OleDbType.DB Date, 0, "creationDate") );
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("creationDat eSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "creationDateSo urce"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("creationIns trument",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "creationInstru ment"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("name",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "name"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("reasonForNo nRecognition",
System.Data.Ole Db.OleDbType.Va rWChar, 0, "reasonForNonRe cognition"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("scheduleTyp e",
System.Data.Ole Db.OleDbType.In teger, 0, "scheduleType") );
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("ScheduleTyp eSource",
System.Data.Ole Db.OleDbType.Va rWChar, 255, "ScheduleTypeSo urce"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("state",
System.Data.Ole Db.OleDbType.In teger, 0, "state"));
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("statusChang e",
System.Data.Ole Db.OleDbType.Va rWChar, 5, "statusChange") );
this.oleDbComma nd3.Parameters. Add(new
System.Data.Ole Db.OleDbParamet er("Original_id ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "id", System.Data.Dat aRowVersion.Ori ginal, null));
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(200, 232);
this.button2.Na me = "button2";
this.button2.Ta bIndex = 1;
this.button2.Te xt = "button2";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.button2 );
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet)).E ndInit();
this.ResumeLayo ut(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void button1_Click(o bject sender, System.EventArg s e)
{
int counthis = dataSet.Predece ssor.Rows.Count ;
DataSet1.Predec essorRow rowtodelete = (DataSet1.Prede cessorRow)
dataSet.Predece ssor.Select("su ccessor=" + 2 + " AND predecessor=" + 1)[0];
dataSet.Predece ssor.RemovePred ecessorRow(rowt odelete);
int counthis2 = dataSet.Predece ssor.Rows.Count ;
MessageBox.Show ("sdsdfsdfs" );
updatethisShit( );
}
private void button2_Click(o bject sender, System.EventArg s e)
{
DataSet1.Predec essorRow rowtoadd =
dataSet.Predece ssor.NewPredece ssorRow();
rowtoadd.predec essor = 1;
rowtoadd.succes sor = 2;
dataSet.Predece ssor.Rows.Add(r owtoadd);
MessageBox.Show ("sdsdfsdfs" );
updatethisShit( );
}
private void updatethisShit( )
{
predecessorAdap ter.Update(data Set);
}
}
}
----------------------------------------------------
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Grant <gp*****@hotmai l.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too