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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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;
DataRow drs= ds.Tables["Employees"].Rows[itemindex];
string dc =drs["EmployeeId"].ToString();
DataRow[] drc= ds2.Tables["TimeAttendance"].Select("EmployeeId = " + dc);
//Delete the selected employee, delete works fine here

===========>>>>//Something is not workoing in this line

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

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


Sign In or Register to comment.