Answered by:
CRUD for gridview to populate data from SQL Server table without primary key

Question
-
User-34860367 posted
Hello,
I got a table without primary key from imported raw data file of the customer information. For example, tblCustomer (Name, phone, address, etc..). I like to build a website page to populate the data into gridview. How do I can add CRUD to allow the user can insert, update and delete records from gridview.
Any example code to show how to get it done, I really appreciate it. Thanks in advance.
Thursday, June 30, 2016 5:11 AM
Answers
-
User1724605321 posted
Hi avt2k7,
Without primary key , how would you identify each record ? I would suggest you could add an IDENTITY column in sql table :
https://msdn.microsoft.com/en-us/library/ms186775(v=sql.105).aspx
You could set it in SSMS :
Then you will find it will be easy to perform CRUD for gridview.
Best Regards,
Nan Yu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 30, 2016 6:22 AM -
User-1034726716 posted
Adding to what Nan Yu said, by default GridView doesn't allow you to perform insert. But you could still add data to it. Take a look at these examples about adding, editing, updating and deleting rows in GridView:
- GridView Insert, Edit, Update and Delete – The Ado.Net way - If using BoundField Columns
- Adding Rows in GridView with Edit, Update and Delete Functionality - If using TemplateField Columns
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 30, 2016 10:53 AM
All replies
-
User1724605321 posted
Hi avt2k7,
Without primary key , how would you identify each record ? I would suggest you could add an IDENTITY column in sql table :
https://msdn.microsoft.com/en-us/library/ms186775(v=sql.105).aspx
You could set it in SSMS :
Then you will find it will be easy to perform CRUD for gridview.
Best Regards,
Nan Yu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 30, 2016 6:22 AM -
User-1034726716 posted
Adding to what Nan Yu said, by default GridView doesn't allow you to perform insert. But you could still add data to it. Take a look at these examples about adding, editing, updating and deleting rows in GridView:
- GridView Insert, Edit, Update and Delete – The Ado.Net way - If using BoundField Columns
- Adding Rows in GridView with Edit, Update and Delete Functionality - If using TemplateField Columns
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 30, 2016 10:53 AM -
User-34860367 posted
Hi all,
I know that the table need a primary key in order to identity the record. and set it by using SSMS. I did several CRUD to perform on table with primary key.
Here is my scenario: my table is imported data from Excel file or raw data file. In my website, we upload the Excel file to temp table, then insert new records into SQL Server table if they are not existed in the table and updated the existed record based on two fields on the table. Therefore, no identical records in the table but can be duplicated fields on rows.
I will add RowId for identify the records as a primary key. Thanks.
Thursday, June 30, 2016 7:48 PM