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

  • Thread starter Thread starter ¹ùÑÇ·æ
  • Start date Start date
¹

¹ùÑÇ·æ

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);
 
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
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.<


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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 ?

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
 
Back
Top