[英]updating is not supported by sqldatasource in asp.net for 3 layered code
我使用3層代碼隱藏和存儲過程來更新gridview。 我在顯示時遇到麻煩,( 除非指定了UpdateCommand,否則數據源'SqlDataSource2'不支持更新。 )但是對數據庫進行了更新。 這是我的代碼
<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>
后面的代碼
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>");
}
}
錯誤消息告訴您,您需要為數據源定義一個UpdateCommand
。
您已經定義了SelectCommand,因此您的應用程序知道如何檢索數據。 但是它不知道如何更新或插入數據,因為您沒有指定它。
檢查您的SQLDataSource並插入適當的命令:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.