How to add Primary key in DataSet

Answers were Sorted based on User's Feedback



How to add Primary key in DataSet..

Answer / kamalakannan.a

If we use c#

DataTable dt=new DataTable();

DataColumn Dc1 = new DataColumn("No", Type.GetType
("System.Int32"));

dt.Columns.Add(Dc1);

//Set Primary key
DataColumn[] dc = new DataColumn[1];
dc[0] = dt.Columns["No"];
dt.PrimaryKey = dc;

Kamal..

Is This Answer Correct ?    34 Yes 7 No

How to add Primary key in DataSet..

Answer / gopi

ds.Tables[0].Constraints.Add("pk_sid",
ds.Tables[0].Columns[0], true);

Is This Answer Correct ?    29 Yes 4 No

How to add Primary key in DataSet..

Answer / shahil singh

dim col() as new dt.datacolumn
col(0)=dt.column(1)
dt.primarykey=col

Is This Answer Correct ?    30 Yes 8 No

How to add Primary key in DataSet..

Answer / r.prajapati

In eidt dataset designer right click on column name which u
want as primary key and set it as pk

Is This Answer Correct ?    19 Yes 14 No

How to add Primary key in DataSet..

Answer / tamilan

This is answer is great. its help me lot.


In eidt dataset designer right click on column name which u
want as primary key and set it as pk

Is This Answer Correct ?    6 Yes 5 No

How to add Primary key in DataSet..

Answer / rajesh bhawsar

dt.PrimaryKey = {dt.Columns(0)}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ADO.NET Interview Questions

What is difference between datareader and dataadapter?

0 Answers  


What are the essential features of ado.net?

0 Answers  


What is difference between sqldatareader and sqldataadapter?

0 Answers  


Differnces between oracle 9i and sql server?

2 Answers   College School Exams Tests, Microsoft,


What is a datatable?

8 Answers   State Bank Of India SBI,






can we have multiple datatables in a datareader ?

18 Answers   Fulcrum Logic, Infosys, Kale Consultants, Ness Technologies,


What are the difference between readonly vs. Const?

0 Answers  


What is data access pattern?

0 Answers  


Can we load multiple tables in a dataset?

0 Answers  


Explain how can we load multiple tables in to dataset?

0 Answers  


If i am expecting a single result from sqlserverdatabase then what command should i follow ?sqlcommand.executereader (commandbehaviour.singleresult)or sqlcommand.executescalar()

4 Answers  


If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?

14 Answers   Ksb,


Categories