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

Add new row in grid with SQLDatasource

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

3 Replies

RU Ragavee U S Syncfusion Team November 14, 2016 12:15 PM UTC

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. 



GU GUYOT November 14, 2016 03:16 PM UTC

Thank you :)


RU Ragavee U S Syncfusion Team November 15, 2016 05:33 AM UTC

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


Loader.
Live Chat Icon For mobile
Up arrow icon