ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

How to find ROW in Dataset / Applying PRIMARY KEY to Dataset

Here is solution how you can apply primary key to your DATASET & using that how can you find particular row from Dataset using that Primary Key.

Note the below given code:

DataSet ds = new DataSet();
DataColumn[] dc = new DataColumn[1];  
//HERE '1' SPECIFY NO. OF PRIMARY KEY. YOU CAN HAVE MORE THEN 1 PRIMARY KEY.
dc[0] = ds.Tables[0].Columns["id"];  //id is Primary Key
ds.Tables[0].PrimaryKey = dc;


Now you can get ROW as given below:

DataRow dr = ds.Tables[0].Rows.Find("1"); 

//Here "1" Specify Primary key.. i.e. Here output will be row whose id=1.

No comments:

Post a Comment