Connecting Tech Pros Worldwide Help | Site Map

why i can not update data in a table without primary key ?

¹ùÑÇ·æ
Guest
 
Posts: n/a
#1: Nov 16 '05
first of all ,i will thank you for reading this . :-)

i am writing a programming to access SQL-SERVER.
i use some codes as follows in order to update data changed in datagrid1.
but i found that it dose not work with a table without primary key.

How can i solve this problem ?

************************************************** *************************
codes:

sqlCMD.CommandText = "SELECT * FROM mytable";
sqlDA.SelectCommand = sqlCMD;
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(sqlDA);
SqlCommandBuilder cmdBuilderEx = new SqlCommandBuilder(sqlDA);
sqlDA.UpdateCommand.Connection = sqlCon;
sqlDA.InsertCommand.Connection = sqlCon;
sqlDA.UpdateCommand = cmdBuilder.GetUpdateCommand();
sqlDA.InsertCommand = cmdBuilderEx.GetInsertCommand();
dataGrid1.DataSource = dataSet2.Tables[0];
sqlDA.Update(dataSet2);



Jeff Louie
Guest
 
Posts: n/a
#2: Nov 16 '05

re: why i can not update data in a table without primary key ?


Without a primary key there is no way to determine which row or rows
(tuples) is to be updated. Without a primary key there is no way to
avoid
duplicate rows. Without a primary key there is no way to enforce a one
to
many parent child relationship between tables.

Regards,
Jeff[color=blue]
>i am writing a programming to access SQL-SERVER.[/color]
i use some codes as follows in order to update data changed in
datagrid1.
but i found that it dose not work with a table without primary key.<


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Marc Scheuner [MVP ADSI]
Guest
 
Posts: n/a
#3: Nov 16 '05

re: why i can not update data in a table without primary key ?


>i am writing a programming to access SQL-SERVER.[color=blue]
>i use some codes as follows in order to update data changed in datagrid1.
>but i found that it dose not work with a table without primary key.
>
>How can i solve this problem ?[/color]

Use a primary key on EVERY TABLE ! It's Database 101 - first lesson!

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Closed Thread