This is a migrated thread and some comments may be shown as answers.

Grid Update and other DML Operations

1 Answer 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahesh
Top achievements
Rank 1
Mahesh asked on 16 Feb 2009, 12:30 PM
Hello,
I am trying to run demo example give on demos section for grid.
But I am getting Error:"incorrect syntax near ?"
I tried for all DML.Same Error.
Thanks in advance.
Here is my aspx:--

<telerik:RadGrid ID="RadGrid2" Skin="Hay" runat="server" CssClass="RadGrid" GridLines="None"
            AllowPaging="True" PageSize="20" AllowSorting="True" Width="99%" AutoGenerateColumns="False"
            ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" DataSourceID="SessionDataSource2" HorizontalAlign="NotSet"
            AllowMultiRowEdit="<%# CheckBox2.Checked %>">
            <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
            <MasterTableView CommandItemDisplay="TopAndBottom" GridLines="None" DataSourceID="SessionDataSource2"
                DataKeyNames="EmployeeID" EditMode="PopUp">
                <Columns>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn UniqueName="TitleOfCourtesy" HeaderText="TOC" DataField="TitleOfCourtesy">
                        <HeaderStyle Width="60px"></HeaderStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LastName" DataField="LastName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="City" HeaderText="City" DataField="City">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="Title" HeaderText="Title" DataField="Title">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column">
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings EditFormType="Template">
                    <FormStyle BackColor="#ECFED8" />
                    <FormTemplate>
                        <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
                            <tr>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    FirstName:</td>
                                <td>
                                    <asp:TextBox ID="TextBox10" Text='<%# Bind( "FirstName") %>' runat="server">
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td>
                                    Last Name:</td>
                                <td>
                                    <asp:TextBox ID="TextBox11" Text='<%# Bind( "LastName") %>' runat="server">
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td>
                                    Title:</td>
                                <td>
                                    <asp:TextBox ID="TextBox12" Text='<%# Bind( "Title") %>' runat="server">
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Country:</td>
                                <td>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind( "Country" ) %>'>
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td>
                                    City:</td>
                                <td>
                                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind( "City") %>'>
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td>
                                    Region:</td>
                                <td>
                                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind( "Region") %>'>
                                    </asp:TextBox></td>
                            </tr>
                            <tr>
                                <td>
                                    Title Of Courtesy</td>
                                <td>
                                    <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("TitleOfCourtesy") %>'
                                        DataSource='<%# (new string[] { "Dr.", "Mr.", "Mrs.", "Ms." }) %>' AppendDataBoundItems="True"
                                        Style="z-index: 1;">
                                        <asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>
                                    </asp:DropDownList></td>
                            </tr>
                        </table>
                        <table style="width: 100%">
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                    </asp:Button>&nbsp;
                                    <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                                    </asp:Button>
                                </td>
                            </tr>
                        </table>
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SessionDataSource2" runat="server"
            ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" ProviderName="System.Data.SqlClient"
            DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = ?" InsertCommand="INSERT INTO [Employees] ([EmployeeID], [LastName], [FirstName], [Title], [TitleOfCourtesy], [City], [Region], [Country]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title], [TitleOfCourtesy], [City], [Region], [Country] FROM [Employees]"
            UpdateCommand="UPDATE [Employees] SET [LastName] = ?, [FirstName] = ?, [Title] = ?, [TitleOfCourtesy] = ?, [City] = ?, [Region] = ?, [Country] = ? WHERE [EmployeeID] = ? ">
            <UpdateParameters>
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="TitleOfCourtesy" Type="String" />
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="Region" Type="String" />
                <asp:Parameter Name="Country" Type="String" />
                <asp:Parameter Name="original_EmployeeID" Type="Int32" />
            </UpdateParameters>
            <DeleteParameters>
                <asp:Parameter Name="original_EmployeeID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="EmployeeID" Type="Int32" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="TitleOfCourtesy" Type="String" />
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="Region" Type="String" />
                <asp:Parameter Name="Country" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <!-- content end -->
    </form>
</body>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2009, 05:57 AM
Hi Mahesh,

Here is codelibrary submission which explains how to perform Insert/Update/Delete operations with SqlDataSource control. Give a try with that and see whether it is working.
Automatic operations with SqlDataSource control

Thanks
Shinu



Tags
Grid
Asked by
Mahesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or