Help: Rows.Remove() in C# .Net not working - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help: Rows.Remove() in C# .Net not working

mostwanted115mostwanted115 Posts: 3Member
Hello. i Am using Visual Studio 2003 .NET and C#. i have a timesheet database. in there are 2 tables: employees and timeattendance. these 2 tables have a common column: employeeID.
On the add employee screen, an employee is added and a new row is created in the employees tabele filled with required fields.similarly, a new row is automatically added to the timeattendance table whenever a new employee is added. the new row in the timeattendance table has the employeeid field filled.
Adding is working perfectly in both tables.
the problem is when deleteing; the row is being deleted from the employees table only and not from the timeattendance table.
Compilation is error-free and no run-time errors exist.Here's the code:
==========================================================================
protected void OnItemClicked(object source, DataGridCommandEventArgs e)
{
//Get the index of the item that was selected
int itemindex = (int)e.Item.ItemIndex;

if (e.CommandName == "Select")
{
//Save the index of the selected item in the view state
ViewState["SelectedItemIndex"] = itemindex;

//Fill the edit boxes with the selected employees name
DataRow selectedRow = ds.Tables["Employees"].Rows[itemindex];
txtNameEdit.Text = selectedRow["Name"].ToString();
txtEmployeeIDUpdate.Text = selectedRow["EmployeeID"].ToString();


//Enable the edit controls
txtNameEdit.Enabled = true;
txtEmployeeIDUpdate.Enabled = true;
btnEmployeeUpdate.Enabled = true;
}
else
{
DataRow drs= ds.Tables["Employees"].Rows[itemindex];
string dc =drs["EmployeeId"].ToString();
DataRow[] drc= ds2.Tables["TimeAttendance"].Select("EmployeeId = " + dc);
try
{
//Delete the selected employee, delete works fine here
ds.Tables["Employees"].Rows[itemindex].Delete();

===========>>>>//Something is not workoing in this line
ds2.Tables["TimeAttendance"].Rows.Remove(drc[0]);

//Update the database
adp.Update(ds, "Employees");
adp2.Update(ds2, "TimeAttendance");

//Update the session DataSet
Session["ds"] = ds;
Session["ds2"] = ds2;
................

Comments

Sign In or Register to comment.