0

Am Updating the gridview with codebehind and stored procedure with 3 layers. I am having trouble while displaying,(Updating is not supported by data source 'SqlDataSource2' unless UpdateCommand is specified.) but updating is done to database. Here is my code

<asp:gridview runat="server" AutoGenerateColumns="False" CellPadding="4" OnRowCommand = "GVEditRate_Command"
    ForeColor="#333333" GridLines="None" ID="GVEditRate" OnRowUpdating ="GVEditRate_OnRowUpdating"
    DataSourceID="SqlDataSource2" >

....

    SelectCommand="SELECT [Bill_Item], [Rate_Cat_Id], [Item_Rate], [Professional_Charge], [Anes_Charge], [Effective_Date] FROM [Rate_M] WHERE (([Active_Flag] = @Active_Flag) AND ([Bill_Item] = @Bill_Item))" >

    <SelectParameters>
        <asp:Parameter DefaultValue="Y" Name="Active_Flag" Type="String" />
        <asp:ControlParameter ControlID="TB_ItemCode" Name="Bill_Item" 
            PropertyName="Text" Type="String" />
    </SelectParameters>

Code behind

protected void GVEditRate_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
    Business bz = new Business();
    rate_data rd = new rate_data();
    rd.itemcode = (GVEditRate.Rows[e.RowIndex].FindControl("Label1") as Label).Text;
    rd.ratecategory = (GVEditRate.Rows[e.RowIndex].FindControl("Label2") as Label).Text;
    string itmrt = (GVEditRate.Rows[e.RowIndex].FindControl("TextBox1") as TextBox).Text;
    rd.itemrate = Convert.ToDouble(itmrt);
    string prf = (GVEditRate.Rows[e.RowIndex].FindControl("TextBox2") as TextBox).Text;
    rd.profesionalchg = Convert.ToDouble(prf);
    string anes = (GVEditRate.Rows[e.RowIndex].FindControl("TextBox3") as TextBox).Text;
    rd.ansthcharge = Convert.ToDouble(anes);
    rd.effective_date = DateTime.Now;
    rd.LogId = Convert.ToDouble(Session["LogId"]);
    rd.ShiftId = Convert.ToInt16(Session["ShiftID"]);
    rd.Userid = Convert.ToString(Session["User"]);
    rd.Actv_flag = "Y";
    int upd_rate = bz.update_rate(rd);
    if (upd_rate > 0)
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "validation",
                "<script language='javascript'>alert('Rate updation successful')</script>");
    }
    else
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "validation",
       "<script language='javascript'>alert('could not update rate')</script>");

    }
}

1 Answer 1

0

The error message ist telling you, that you need to define a UpdateCommand for your datasource.

You have defined a SelectCommand, so your application knows how to retrieve data. But it does not know how to update or insert data, since you did not have it specified.

Check your SQLDataSource and insert the appropriate command:

<asp:SqlDataSource
     id="SqlDataSource2"
     runat="server"
     SelectCommand="SELECT [Bill_Item], [Rate_Cat_Id], [Item_Rate], [Professional_Charge], [Anes_Charge], [Effective_Date] FROM [Rate_M] WHERE (([Active_Flag] = @Active_Flag) AND ([Bill_Item] = @Bill_Item))"
     UpdateCommand="INSERT Stored Procedure here">
     UpdateCommandType="StoredProcedure"
      /* ... */>
       <UpdateParameters>                
            <asp:Parameter Direction="Output" Name="Name1" Type="Int32" />
            <asp:Parameter Direction="Output" Name="Name2" Type="Int32" />
            <asp:Parameter Direction="Output" Name="Name3" Type="Int32" />
       </UpdateParameters>
</asp:SqlDataSource>
Sign up to request clarification or add additional context in comments.

2 Comments

but am using a stored procedure which needs few more parameters to be supplied from code behind
Define your Stored Proc as the update command and then add your parameters from codebehind to your SQLDataSource UpdateCommand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.