tags:

views:

40

answers:

2

I am working on windows application using c# and MySQL. I inserted new record by reading text file into MySQL database, Database having no primary key but combination of four columns we can consider as component of primary key (but actually database having no primary key). I know how to add and update record using DataAdapter and DataSet. But I can not update a record in the database having no primary key.

Can you please guide me, how can I update a record in the database with a database having no primary key.

Thanks.

+1  A: 

Assuming you have next table:

column1,
column2,
..
columnN,
target -- column to update

then use:

UPDATE table
SET
   target = @target
WHERE
   column1 = @va1, column2 = @val, -- etc specify all columns in table

If you have duplicated (absolute equal) records, you will update all of them.

abatishchev
Thanks abatishchev,but i am expecting something like -myDataRow["TranID"] = strTranRC;myDataRow["Message"] = strMessage.Trim();DSet.Tables["LOGData"].Rows.Add(myDataRow);ODBCDADP.Update(DSet, "LOGData");Is it possible to write such code for updating(we can write if primary key is present but in this case primary key is not present), instead of writing a query and passing a values into query because we can not check in query whether a value is null (for decimal type of variable).Thanks/Prabhat
+1  A: 

For this to work with a Dataset you need to define your update command "By-Hand".

You need to set the proper DataAdapter.UpdateCommand.

In my point of view it would be a better approach to just add a primary key column to the table.

Yves M.
I tried by create update command and then set the parameters for @paramenters in query, code executed but no data updated...I guess its little bit difficult to do such data updation. Finally I did it by spefifying command object and Command.ExecuteNonQuery() Method, I generated querystring dynamically now its working perfactely....Thanks for your help...!!! :)