Question Primary key

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Experts

How to apply primary key on sno column in the following dataset

VB.NET:
  dim sql = "select * from employees"
        Dim da As new SqlClient.SqlDataAdapter (sql,con)
        'ds.Clear()
        da.Fill(ds, "employees")
        TextBox1.DataBindings.Add("text", ds.Tables("employees"), "sno")
        TextBox2.DataBindings.Add("text", ds.Tables("employees"), "Name")
        TextBox3.DataBindings.Add("text", ds.Tables("employees"), "City")
        TextBox4.DataBindings.Add("text", ds.Tables("employees"), "Phone")

Please help
 
If you set the MissingSchemaAction property of the DataAdapter to AddWithKey then it will use the same PK information as the database. Otherwise, you can set the PrimaryKey of the DataTable using an array containing the appropriate DataColumn(s).
 
How to apply primary key using array?

I want to add primary key on first column that is sno

Please help
 
Dear Sir

I use this line to add primary key on my dataset
VB.NET:
  ds.PrimaryKey = New DataColumn() {ds.Columns("sno")}
it says
'Primarykey' is not a member of 'system.data.dataset'

How to modify codes?
 
'Primarykey' is not a member of 'system.data.dataset'

No, it is a member of System.Data.DataTable

A dataset is a colelction of datatables.. Like a database is a collection of tables. Databases don't have primary keys, tables do..

Make this distinction in your mind, very clearly between what is a DataSet and what is a DataTable, otherwise you'll cause much frustration and confusion among fellow developers when using these words incorrectly.
 
No, it is a member of System.Data.DataTable
Indeed, which is why post #2 and post #4 both say DataTable.

For more information on the roles of each ADO.NET data container, click here.
 
I think the subtlety is often lost ;)
I think it's actually that people don't read properly. This is not an isolated case but far too many people read what they think they're reading rather than what's actually written. It's a common human failing but I figure that, if you ask the question, you have a responsibility to read the answer fully and carefully.
 
In exam halls the world over, students will read and answer the question they want to see and write about, rather than what is asked.. I don't think the phenomenon will stop any time soon :/
 
Back
Top