|
I was in a hurry, some garbage code, now remove those useless codes!
You can take another look and add some notes!
// Declare the DB connection object
public OleDbConnection cn = new OleDbConnection ();
// After executing the following function, the value here is all the ChildID you want !!!
public ArrayList aryAllChildID = new ArrayList ();
public void GetAllChildID (string paID)
{
// Put each ID here!
aryAllChildID.Add (paID)
// Of course, here you can delete the DB directly according to the incoming ID! Remember to write down this ID, and use it to find out if it has a sub-ID!
.......... delete from table_name where id = paid
..........
string strTmpRootID = paID; // No longer delete here, don't need this sentence!
// Store SQL statement
string sql = "SELECT ID FROM TABLE_NAME WHERE PARENTID = '" + paID + "'";
cn.ConnectionString = "Provider = ...................";
// Open the connection
cn.Open ();
// Declare the Command object
OleDbCommand oCmd = new OleDbCommand (sql, cn);
// Declare to store the returned data set object
OleDbDataReader oDr = new OleDbDataReader ();
// Get the return data
oDr = oCmd.ExecuteReader (CommandBehavior.CloseConnection);
if (oDr.HasRows)
{
while (oDr.Read ())
{
string strTmpID = Convert.ToString ((oDr ["ID"] == System.DBNull.Value)? String.Empty: oDr ["ID"]);
// If it is not empty, iterate. If your DB defines id + parentid as PK, you don't need the following conditions to judge!
if (strTmpID! = String.Empty)
{
GetAllChildID (strTmpID);
}
}
}
} |
|