7 Replies - 2280 Views - Last Post: 20 March 2009 - 06:40 PM Rate Topic: -----

#1 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

How can I delete a specific row in a table

Posted 13 March 2009 - 06:41 PM

How can I delete or remove a specific row in a table by using only one if data as a reference

I tried this code but it only delete a column

  #region fill datagrid

			WebReferences.CSCService.Service1.Service1 service =
					new WebReferences.CSCService.Service1.Service1();
			WebReferences.CSCService.Service1.DataSetResult ds =
				service.GetUserInfo(string.Empty, string.Empty, string.Empty);
			ds.ResultData.Tables[0].Columns.RemoveAt(1);

			dtgAccountlist.DataSource = new DataView(ds.ResultData.Tables[0]);
			
   
			dtgAccountlist.DataBind();


Is This A Good Question/Topic? 0
  • +

Replies To: How can I delete a specific row in a table

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How can I delete a specific row in a table

Posted 13 March 2009 - 07:41 PM

Replace 'Columns' with 'Rows'.

ds.ResultData.Tables[0].Rows.RemoveAt(1);


Was This Post Helpful? 0
  • +
  • -

#3 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: How can I delete a specific row in a table

Posted 13 March 2009 - 07:43 PM

how about deleting a row that if it contain this string that row will be deleted
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How can I delete a specific row in a table

Posted 14 March 2009 - 09:44 AM

Then you will need to iterate through all the rows with some type of loop, until you find the row that you want to delete. Get the index number of that row, leave the loop and then delete the row.
Was This Post Helpful? 0
  • +
  • -

#5 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: How can I delete a specific row in a table

Posted 14 March 2009 - 07:08 PM

sample codes please
Was This Post Helpful? 0
  • +
  • -

#6 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: How can I delete a specific row in a table

Posted 18 March 2009 - 11:18 PM

please help
Was This Post Helpful? 0
  • +
  • -

#7 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How can I delete a specific row in a table

Posted 19 March 2009 - 08:45 AM

Did you even try to do it yourself?

Here is an example of what I was referring to. Once the loop has exited you will have the row number from the dataset.
string dataToFind = "something";
int rowNumber = 0;

foreach(DataRow dr in ds.ResultData.Tables[0].Rows)
{
	 if (dataToFind.Equals(dr["columnName"]))
		  break; //exit the loop, the correct row has been found

	 rowNumber++; //Didn't find a match yet, increment the counter
}

Was This Post Helpful? 0
  • +
  • -

#8 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: How can I delete a specific row in a table

Posted 20 March 2009 - 06:40 PM

tnx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1