1

我使用 GridView 并从这里我想插入更新。我已经完成了我的工作,但是当我使用具有数字数据类型的 RchPaidAmt 字段时,会显示以下消息:编译器错误消息:CS0029:无法将类型“十进制”隐式转换为“字符串”

数据类型

RchID                     int           
RchAppID                  int           
RchCallDate               datetime             
RchComments               varchar(150)       
RchAttemptCall            int           
RchReceivedParty          varchar(50)         
RchPrmTaken               int           
RchCNPrm                  int           
RchNxtPrmDate             datetime             
RchPaidAmt                numeric(18, 2)


<UpdateParameters>
                    <asp:Parameter Name="RchAppID" Type="Int32" />
                    <asp:Parameter Name="RchCallDate" Type="DateTime" />
                    <asp:Parameter Name="RchComments" Type="String" />
                    <asp:Parameter Name="RchAttemptCall" Type="Int32" />
                    <asp:Parameter Name="RchReceivedParty" Type="String" />
                    <asp:Parameter Name="RchPrmTaken" Type="Int32" />
                    <asp:Parameter Name="RchCNPrm" Type="Int32" />
                    <asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
              <asp:Parameter Name="RchPaidAmt" Type="Decimal" />   
</UpdateParameters>





protected void GVCallHistory_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Add")
        {
            string strRchAppID = hfRchAppID.Value;
            string strRchCallDate = DateTime.Parse(Convert.ToString(DateTime.Now)).ToString("dd MMM yyyy HH:MM");
            string strRchComments = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchComments") as TextBox).Text;
            string strRchAttemptCall = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchAttemptCall") as TextBox).Text;            
            string strRchReceivedParty = ((e.CommandSource as Button).NamingContainer.FindControl("DDLRchReceivedParty") as DropDownList).SelectedValue;
            string strRchPrmTaken = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchPrmTaken") as TextBox).Text;
            string strRchCNPrm = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchCNPrm") as TextBox).Text;
            string strRchNxtPrmDate = "";
            if (Convert.ToString(((e.CommandSource as Button).NamingContainer.FindControl("txtRchNxtPrmDate") as TextBox).Text) !="")
            {
                strRchNxtPrmDate = DateTime.Parse(Convert.ToString(((e.CommandSource as Button).NamingContainer.FindControl("txtRchNxtPrmDate") as TextBox).Text)).ToString("dd MMM yyyy");
            }
            else
            {
                strRchNxtPrmDate = "01Jan1900";
            }

            **string strRchPaidAmt = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchPaidAmt") as TextBox).Text;**

            DSCallHistory.InsertParameters["RchAppID"].DefaultValue = DateTime.Parse(Convert.ToString(DateTime.Now)).ToString("dd MMM yyyy HH:MM");// strRchAppID;
            DSCallHistory.InsertParameters["RchCallDate"].DefaultValue = strRchCallDate;
            DSCallHistory.InsertParameters["RchComments"].DefaultValue = strRchComments;
            DSCallHistory.InsertParameters["RchAttemptCall"].DefaultValue = strRchAttemptCall;
            DSCallHistory.InsertParameters["RchReceivedParty"].DefaultValue = strRchReceivedParty;
            DSCallHistory.InsertParameters["RchPrmTaken"].DefaultValue = strRchPrmTaken;
            DSCallHistory.InsertParameters["RchCNPrm"].DefaultValue = strRchCNPrm;
            DSCallHistory.InsertParameters["RchNxtPrmDate"].DefaultValue = strRchNxtPrmDate;

            **if (strRchPaidAmt !=null)
            {
                DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt);
            }
            else
            {
                DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue ="0";
            }**
            DSCallHistory.Insert();
        }
    }



what should I do. Pls suggest me with best solution.

Thanks
Nur

附加信息

 <asp:SqlDataSource ID="DSCallHistory" runat="server" 
                ConflictDetection="CompareAllValues" 
                ConnectionString="<%$ ConnectionStrings:OptimaWebCustomerQueryCon %>" 
                DeleteCommand="DELETE FROM [TblRecCallHistory] WHERE [RchID] = @RchID" 
                InsertCommand="INSERT INTO [TblRecCallHistory] ([RchAppID], [RchCallDate], [RchComments], [RchAttemptCall], [RchReceivedParty], [RchPrmTaken], [RchCNPrm], [RchNxtPrmDate], [RchPaidAmt]) VALUES (@RchAppID, @RchCallDate, @RchComments, @RchAttemptCall, @RchReceivedParty, @RchPrmTaken, @RchCNPrm, @RchNxtPrmDate, @RchPaidAmt)" 
                OldValuesParameterFormatString="original_{0}" 
                SelectCommand="SELECT [RchID], [RchAppID], [RchCallDate], [RchComments], [RchAttemptCall], [RchReceivedParty], [RchPrmTaken], [RchCNPrm], 
                [RchNxtPrmDate]=(case when [RchNxtPrmDate] = '01Jan1900' then NULL else [RchNxtPrmDate] end),
                [RchPaidAmt] FROM [TblRecCallHistory] WHERE ([RchAppID] = @RchAppID) ORDER BY [RchID]" 
                UpdateCommand="UPDATE [TblRecCallHistory] SET [RchAppID] = @RchAppID, [RchCallDate] = @RchCallDate, [RchComments] = @RchComments, [RchAttemptCall] = @RchAttemptCall, [RchReceivedParty] = @RchReceivedParty, [RchPrmTaken] = @RchPrmTaken, [RchCNPrm] = @RchCNPrm, [RchNxtPrmDate] = @RchNxtPrmDate, [RchPaidAmt] = @RchPaidAmt WHERE [RchID] = @RchID">
                <DeleteParameters>
                    <asp:Parameter Name="RchID" Type="Int32" />

                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="RchAppID" Type="Int32" />
                    <asp:Parameter Name="RchCallDate" Type="DateTime" />
                    <asp:Parameter Name="RchComments" Type="String" />
                    <asp:Parameter Name="RchAttemptCall" Type="Int32" />
                    <asp:Parameter Name="RchReceivedParty" Type="String" />
                    <asp:Parameter Name="RchPrmTaken" Type="Int32" />
                    <asp:Parameter Name="RchCNPrm" Type="Int32" />
                    <asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
                    <asp:Parameter Name="RchPaidAmt" Type="Decimal" />
                </InsertParameters>
                <SelectParameters>
                    <asp:ControlParameter ControlID="GVRecList" Name="RchAppID" 
                        PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="RchAppID" Type="Int32" />
                    <asp:Parameter Name="RchCallDate" Type="DateTime" />
                    <asp:Parameter Name="RchComments" Type="String" />
                    <asp:Parameter Name="RchAttemptCall" Type="Int32" />
                    <asp:Parameter Name="RchReceivedParty" Type="String" />
                    <asp:Parameter Name="RchPrmTaken" Type="Int32" />
                    <asp:Parameter Name="RchCNPrm" Type="Int32" />
                    <asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
                    <asp:Parameter Name="RchPaidAmt" Type="Decimal" />
                </UpdateParameters>
            </asp:SqlDataSource>
4

3 回答 3

0
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue ="0";

应该:

DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue =0m;
于 2013-09-25T11:13:48.437 回答
0

decimal在将其分配给之前不要转换您的值DefaultValue-DefaultValue需要一个字符串,即

DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = strRchPaidAmt;
于 2013-09-25T11:14:21.837 回答
0

更改以下代码行

DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt);

成为 :

DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt).ToString();

问题是您试图将小数设置为字符串对象。

编辑:詹姆斯的解决方案可能更合适。

于 2013-09-25T11:14:27.427 回答