Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

this is the way i find out if i have added a row to a dataset or not. there is a boolean value and after the row is added for the first time i set the value to false, so the next time the row is edited rather than added again. i can do this as the dataset is empty when i start, and i am only adding one row. im sure there is a more professional and better way to do this. can anyone tell me how they do it?

 

 

if(workRecordCreated == false)
{
workRow = ds.Tables["work_details"].NewRow();
workRow["patient_id"] = guid;
workRow["sitting"] = this.chkSit.Enabled;
workRow["details"] = this.details.text;
}

else
{

ds.Tables["work_details"].Rows[ds.Tables["work_details"].Rows.Count-1].BeginEdit();
ds.Tables["work_details"].Rows[ds.Tables["work_details"].Rows.Count-1]["sitting"] = this.chkSit.Enabled;
ds.Tables["work_details"].Rows[ds.Tables["work_details"].Rows.Count-1]["details"] = this.details.text;
ds.Tables["work_details"].Rows[ds.Tables["work_details"].Rows.Count-1].EndEdit();
}

Posted

1. DataTable has got property called PrimaryKey and then use DataTable.Rows.Find()

 

2. DataTable.Select() has two very usefull overloads and then count on the Rows>0

 

Hope this helps

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...