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.
Unfortunately, activation email could not send to your email. Please try again.

Add new row in grid with SQLDatasource

Thread ID:

Created:

Updated:

Platform:

Replies:

127389 Nov 11,2016 10:11 AM Nov 15,2016 12:33 AM ASP.NET Web Forms 3
loading
Tags: Grid
GUYOT
Asked On November 11, 2016 10:11 AM

Hello,

how can i add a new row directly from my grid :

Here is my code (very simple)

<ej:Grid ID="Grid1" runat="server" CssClass="" DataSourceCachingMode="None" DataSourceID="SqlDataSource1" EnableLoadOnDemand="False" MinWidth="0">
        <Columns>
            <ej:Column DataType="number" Field="id" IsPrimaryKey="True">
            </ej:Column>
            <ej:Column DataType="string" Field="Client">
            </ej:Column>
        </Columns>
    </ej:Grid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" DeleteCommand="DELETE FROM [TaClients] WHERE [id] = @original_id AND [Client] = @original_Client" InsertCommand="INSERT INTO [TaClients] ([id], [Client]) VALUES (@id, @Client)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [TaClients]" UpdateCommand="UPDATE [TaClients] SET [Client] = @Client WHERE [id] = @original_id AND [Client] = @original_Client">
        <DeleteParameters>
            <asp:Parameter Name="original_id" Type="Int32" />
            <asp:Parameter Name="original_Client" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="Client" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Client" Type="String" />
            <asp:Parameter Name="original_id" Type="Int32" />
            <asp:Parameter Name="original_Client" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

Thank you

Ragavee U S [Syncfusion]
Replied On November 14, 2016 07:15 AM

Hi Guyot, 

We have created a sample to insert a record to database from grid using the SqlDataSource InsertCommand property, which can be downloaded from the below location. 


In the above sample, since the IsIdentity property for the primaryKey column is set, it is not necessary to define the column within the InsertCommand property as the column value will be automatically generated and thus will conflict with the value we pass. 

So please ensure in your sample project also, if the IsIdentity property is set for the column in the database table and accordingly pass the values in the InsertCommand property. 

Regards, 
Ragavee U S. 


GUYOT
Replied On November 14, 2016 10:16 AM

Thank you :)

Ragavee U S [Syncfusion]
Replied On November 15, 2016 12:33 AM

Hi Guyot, 
  
Thanks for your update. 
 
Please let us know if you need any further assistance on this. 
  
Regards, 
Ragavee U S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;