We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to add new row to db?

I have tried to understand how the "AddNewRow" example works but I can't understand how the data is modified and how I can add the data to the DB when the row is complete.

4 Replies

GE GeorgeNas May 23, 2019 07:42 PM UTC

Your question is a valid one but let me note the following

Lets asume you manage the addrow method

What it actually does it adds a new row in your grid and the related dataset
But when you try to update your database table you might come up with problems relating to data validation 

What  will happen if you have a DB table with a primary key that is a uniqueidentifier?? 

Of course in your grid you dont display a column that contains a uniqueidentifier value and of course you need to create a new value for it

My experience suggests the following

When you need to add data to a table underlying to a grid take control through code
My practice is to have a form that opens for the following actions
  • Addnew record
  • View record details ( because on the grid you may display a subset of the fields of the  entire record)
  • Update Record 
Shown bellow the case of addnew record

On Save button click validate all data supplied by the user 

Besides the shown 3 fields that require user data, and also are the only 3 fields shown in the datagrid, exist 5 other fields in the particular table that get values when user data validation is succesfull a and are reuired fields in the database table 

Id which is  of type uniqueindentifier and its value is created using code
DateCreated which is a field that gets the current date value on the save action
IdUsed which is a field that gets the value 0 on the save action but it is modified later in the application and notifies something 
LastUserUpdated that takes the guid of the user that performed the action
LastDateModified  that takes date value when the record is modified

Bellow shown the result of failed user data validation

The fields with wrong data are displayed with red color and ** 
The user should have entered an integer value in the field Unit Period and decimal value in the field  Charge Value

Data validation informs the user of his error and avoids crashing due to SQL validation when you will try to add an invalid record

My suggestion is to take control using code when adding data to a db table 

The grids and all the wonderfull components syncfusion has created are wonderfull for data representation and orgnization 

BUT when it comes to adding data to a database I use code validation and I suggest you do the same

JP Jagadeesan Pichaimuthu Syncfusion Team May 24, 2019 10:11 AM UTC

Hi Iván, 
Thanks for using Syncfusion products. 
By default, while entering to the AddNewRow into the edit mode, A new instance will be created for the underlying data object. This instance will be committed to the underlying source once the editing is completed for the row. Refer to the following UG document, 
If you want to commit the changes to the DB once the editing is completed for the record, you can use the RowValidating and RowValidated events. These events will be fired once the row is leaving the editing after modifying the data of it. Refer to the following UG document, 

IV Iván May 24, 2019 07:06 PM UTC

Thank you so much, I've used the information of RowValidating & RecordDeleting to manage the data into DB.

JP Jagadeesan Pichaimuthu Syncfusion Team May 27, 2019 08:42 AM UTC

Hi Iván, 
Thanks for the update. 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Live Chat Icon For mobile
Up arrow icon