Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem during insertion of records from DataGridView
 

Problem during insertion of records from DataGridView

Hi,

I am beginner in .NET C#. I have a problem with insertion new records from existing. I have a three records in a table with composite primary key as sID + SrNo.
sID SrNo sName
1 1 Name1
1 2 Name2
1 3 Name3

I am showing this records DataGridView by giving the DataSource = DataSet(ds) and want to save the replica of this with changed sID = 2.
But when I am calling the DataAdapter.Update(ds) it deleting the records of sID = 1 and inserting the new records of sID = 2. But I want all records of sID = 1 with this new records of sID = 2.

Can you help me to achieve this or suggest me the best path?

Regards,
Ankur
Ankur
  • Moved byVMazurMVPTuesday, March 03, 2009 11:15 AM (Moved from ADO.NET DataSet to Windows Forms Data Controls and Databinding)
  •  
Ankurmutha  Wednesday, February 25, 2009 11:45 AM
Hi Ankur,

Base on my understanding, you want to change the value of column sID. There are two ways:

1. If you want to use sqlCommant to update the DataSource, use the following:

"update test01 set sid = 2 ";

2. If you change the value (set the cells of the sID column to 2 manually) in the DataGridView, and save the changes, you can try the following code to update the changes to the DataBase:

.test01TableAdapter.Update(factoryDataSet3);

If I misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, March 04, 2009 3:23 AM
Hi Ankur,

Base on my understanding, you want to change the value of column sID. There are two ways:

1. If you want to use sqlCommant to update the DataSource, use the following:

"update test01 set sid = 2 ";

2. If you change the value (set the cells of the sID column to 2 manually) in the DataGridView, and save the changes, you can try the following code to update the changes to the DataBase:

.test01TableAdapter.Update(factoryDataSet3);

If I misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, March 04, 2009 3:23 AM
Hi Ling,

Thanks for reply.

I want records of both sID 1 & 2. In other words, I want to insert the record of sID 2.

Please do the needful.

Thanks,
Ankur

Ankur
Ankurmutha  Thursday, July 23, 2009 8:22 AM

You can use google to search for other answers

Custom Search

More Threads

• i want update SQl statment for updating all dataset manually
• Can ObjectDataSource attributes be used in Winform?
• LET THE ARGUMENT BEGIN: TO STRONGLY TYPE OR NOT TO STRONGLY TYPE
• have problem "Object reference not set to an instance of an object."
• DataGridView - Select row programatically
• Needed to reload operating system and have to reload SQL.
• RowLeave event happens before CellValueChanged
• DataTable RowChanged Event
• using datagridview in .net 1.1
• Solved with examplecode: datagrid question .net 2003