2

我开发了一个如下页面:

<table>
    <tr>
            <td align="right">  Collection Area</td>
            <td>   :</td>
            <td align="left">  
             <asp:CheckBoxList ID="ChkCollAreaNewFile" runat="server">
                <asp:ListItem Value="Retail Banking Division">Retail Banking Division</asp:ListItem>
                <asp:ListItem Value="Chittagong Zone">Chittagong Zone</asp:ListItem>
                <asp:ListItem Value="Khulna">Khulna</asp:ListItem>
                <asp:ListItem Value="Sylhet">Sylhet</asp:ListItem>
                <asp:ListItem Value="Rajshahi">Rajshahi</asp:ListItem>
                <asp:ListItem Value="Barisal">Barisal</asp:ListItem>
                </asp:CheckBoxList>


            </td>
            <td align="right"> Disbursed Area</td>
            <td>  &nbsp;</td>
            <td align="left" style="margin-left: 40px">
                <asp:CheckBoxList ID="ChkDisbAreaNewFile" runat="server" 
                    DataSourceID="DSDisbAreaNewFile" DataTextField="RegionName" 
                    DataValueField="RegionName">
                </asp:CheckBoxList>
                <asp:SqlDataSource ID="DSDisbAreaNewFile" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:OptimaWebCustomerQueryCon %>" 
                    SelectCommand="SELECT [RegionName] FROM [DDRegion]"></asp:SqlDataSource>
            </td>
            <td> &nbsp;</td>
        </tr>
    <tr>
            <td align="right">  &nbsp;  Loan Type</td>
            <td>   &nbsp;:</td>
            <td align="left">  
               <asp:DropDownList ID="DDLLoanTypeNewFile" runat="server" AppendDataBoundItems="true" 
                    DataSourceID="DSAssignCELoanType" DataTextField="LType" DataValueField="LType">
                    <asp:ListItem Value="%">-Select-</asp:ListItem>
                </asp:DropDownList>
                <asp:SqlDataSource ID="DSAssignCELoanType" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:OptimaWebCustomerQueryCon %>" 
                    SelectCommand="SELECT [LType] FROM [DDLoanType] ORDER BY [LType]">
                </asp:SqlDataSource> 
            </td>
            <td align="right"> Cycle</td>
            <td>  :</td>
            <td align="left">
                <asp:DropDownList ID="DDLCycleNewFile" runat="server">
                <asp:ListItem Value="">-Select-</asp:ListItem>
                <asp:ListItem Value="X">X</asp:ListItem>
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
                <asp:ListItem Value="6">6</asp:ListItem>
                <asp:ListItem Value="7">7</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td> &nbsp;</td>
        </tr>
    <tr>
            <td align="right">  &nbsp;</td>
            <td>   &nbsp;</td>
            <td align="left">  
                <asp:Label ID="lblMsBx" runat="server" Text="Label"></asp:Label>
            </td>
            <td align="right"> 
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
            <td>  &nbsp;</td>
            <td align="right" style="margin-left: 40px">
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <asp:Button ID="btnRankUpdate" runat="server" Text="Update" 
                    onclick="btnRankUpdate_Click"/>
            </td>
            <td> &nbsp;</td>
        </tr>

    <tr>
            <td align="right">  &nbsp;</td>
            <td>   &nbsp;</td>
            <td align="left">  
                &nbsp;</td>
            <td align="right"> &nbsp;</td>
            <td>  &nbsp;</td>
            <td align="right" style="margin-left: 40px">
                &nbsp;</td>
            <td> &nbsp;</td>
        </tr>

</table>

当我按下按钮时,我的存储过程将运行并更新记录。我的存储过程如下:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[WebRecNewFileAssign] 
@ParmAppLoanType varchar(100),
@ParmBRegion varchar(1000), --Disbursed Area
@ParmUserBrDiv varchar(1000), -- Collection Area
@AssingCycle varchar(100)
as
begin
DECLARE db_cursor CURSOR FOR 
SELECT  dbo.TblDisburseInfo.DisbID FROM dbo.TblDisburseInfo INNER JOIN
    dbo.TblMasterInfo ON dbo.TblDisburseInfo.DisbAppID = dbo.TblMasterInfo.AppID
    WHERE (dbo.TblDisburseInfo.DisbRecAssignTo IS NULL) AND (dbo.TblMasterInfo.AppLoanType = @ParmAppLoanType) AND 
    (dbo.TblDisburseInfo.DisbBr in(SELECT BrName FROM DDBranchName Where BRegion in(@ParmBRegion) ))
    ORDER BY dbo.TblDisburseInfo.DisbAmt DESC

  declare @tdisbid as int
  declare @cnt as int
  set @cnt = 1
  declare @maxcnt as int

  select @maxcnt = MAX(reid) from [dbo].[TblRecAssignName] WHERE ReAssignName in (SELECT LogId FROM TblUserTest 
        where UserBrDiv in(@ParmUserBrDiv) AND ReCycle=@AssingCycle)

  OPEN db_cursor   
      FETCH NEXT FROM db_cursor INTO @tdisbid   

      WHILE @@FETCH_STATUS = 0   
          BEGIN   
               update [OptimaUCBL].[dbo].[TblDisburseInfo]
               set DisbRecAssignTo = (select ReAssignName from [OptimaUCBL].[dbo].[TblRecAssignName] 
                    where [ReID] = @cnt AND ReAssignName in (SELECT LogId FROM TblUserTest 
                    where UserBrDiv in (@ParmUserBrDiv) AND ReCycle=@AssingCycle))
               where [DisbID] = @tdisbid

               if @cnt = @maxcnt 
                  set @cnt = 1
               else 
                  set @cnt = @cnt + 1                      

               FETCH NEXT FROM db_cursor INTO @tdisbid   
          END   

      CLOSE db_cursor   
      DEALLOCATE db_cursor

end

最后是我的代码(C#)::

 protected void btnRankUpdate_Click(object sender, EventArgs e)
    {
        string myDisbArea = "";
        for (int i = 0; i < ChkDisbAreaNewFile.Items.Count; i++)
        {
            if (ChkDisbAreaNewFile.Items[i].Selected)
            {
                myDisbArea = myDisbArea + "'" + ChkDisbAreaNewFile.Items[i].Value + "' ,";
            }
        }
        string NewDisbAreaNewFile = myDisbArea.Substring(myDisbArea.Length - (myDisbArea.Length), (myDisbArea.Length - 1));           
        string AreaSelected = "";
        for (int i = 0; i < ChkCollAreaNewFile.Items.Count; i++)
        {
            if (ChkCollAreaNewFile.Items[i].Selected)
            {
                AreaSelected = AreaSelected + "'" + ChkCollAreaNewFile.Items[i].Value + "' ,";
            }
        }
        string NewAreaSelected = AreaSelected.Substring(AreaSelected.Length - (AreaSelected.Length), (AreaSelected.Length - 1));


            String strConnString = ConfigurationManager.ConnectionStrings["OptimaWebCustomerQueryCon"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand com = new SqlCommand();
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "WebRecNewFileAssign";
            com.Parameters.AddWithValue("@ParmAppLoanType", SqlDbType.VarChar).Value = DDLLoanTypeNewFile.SelectedValue;
            com.Parameters.AddWithValue("@ParmBRegion", SqlDbType.VarChar).Value = Convert.ToString(NewDisbAreaNewFile);
            com.Parameters.AddWithValue("@ParmUserBrDiv", SqlDbType.VarChar).Value = Convert.ToString(NewAreaSelected);
            com.Parameters.AddWithValue("@AssingCycle", SqlDbType.VarChar).Value = DDLCycleNewFile.SelectedValue;
            com.Connection = con;
            try
            {
                con.Open();
                com.ExecuteNonQuery();
                lblMsBx.Text = "Record updated successfully";
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
    }

当我按下更新按钮Record updated successfully消息显示但记录没有更新。我的问题在哪里,我无法确定。请支持我。

谢谢

4

2 回答 2

0

问题是该IN子句where UserBrDiv in(@ParmUserBrDiv)不会像那样工作,因此实际上没有选择任何记录。您在两个不同的地方使用它,获取@maxcnt,因为它总是为零,然后尝试更新实际的表,它永远不会因为它而选择任何行。您需要做的是在您的数据库中构建此 UDF:

IF OBJECT_ID('dbo.CSVToTable') IS NOT NULL
    DROP FUNCTION dbo.CSVToTable

GO

CREATE FUNCTION [dbo].[CSVToTable]
(
    @KeyValue VARCHAR(8000),
    @StringInput VARCHAR(8000)
)
RETURNS @OutputTable TABLE
(
    [KeyValue] VARCHAR(8000),
    [String] VARCHAR(8000)
)
AS
BEGIN

    DECLARE @String VARCHAR(10)

    WHILE LEN(@StringInput) > 0
    BEGIN
        SET @String = LEFT(@StringInput, 
            ISNULL(NULLIF(CHARINDEX(',', @StringInput) - 1, -1),
            LEN(@StringInput)))
        SET @StringInput = SUBSTRING(@StringInput,
            ISNULL(NULLIF(CHARINDEX(',', @StringInput), 0),
            LEN(@StringInput)) + 1, LEN(@StringInput))

        INSERT INTO @OutputTable ( [KeyValue], [String] )
        VALUES ( @KeyValue, @String )
    END

    RETURN
END

GO

然后将此语句放在您需要修复的第一个查询之上:

SELECT String
INTO #brdiv
FROM dbo.CSVToTable(@ParmUserBrDiv)

然后将您的查询更改为:

SELECT @maxcnt = MAX(reid)
FROM [dbo].[TblRecAssignName]
WHERE ReAssignName in (
    SELECT LogId
    FROM TblUserTest
    WHERE UserBrDiv IN (
        SELECT String
        FROM #brdiv
    ) AND ReCycle=@AssingCycle)

UPDATE [OptimaUCBL].[dbo].[TblDisburseInfo]
SET DisbRecAssignTo = (
    SELECT ReAssignName
    FROM [OptimaUCBL].[dbo].[TblRecAssignName]
    WHERE [ReID] = @cnt AND
        ReAssignName in (
            SELECT LogId
            FROM TblUserTest
            WHERE UserBrDiv IN (
                SELECT String
                FROM #brdiv
            ) AND ReCycle=@AssingCycle
        )
)
WHERE [DisbID] = @tdisbid

最后,从逗号分隔的字符串中删除单引号,并像这样分隔值:

A,B,C,D,E,F,G
于 2013-08-27T12:54:33.187 回答
0

块引用

只需更改存储过程,如下所示:

Declare @AppName varchar(100) ='Rahman',
-- @AppID int ='%',
 @AppLoanType  varchar(100)='Auto Loan',
 @AppSourceBrName varchar(100)='%',
 @AppSourceCode varchar(100)='%',
 @AppLoanStatus varchar(100)='%',
 @AppAsignTo varchar(100)='%',
 @DisbAcSb varchar(100)='%',
 @DisbAcLoan varchar(100)='%',
 --@DisbDate varchar(100)='01Jan1990',
 --@DisbDate2 varchar(100)='01Dec2013',
 --@DisbExpDate varchar(100)='01Jan1990',
 --@DisbExpDate2 varchar(100)='01Dec2013',
 -- @DisbEMIDate varchar(100)='01Jan1990',
 --@DisbEMIDate2 varchar(100)='01Dec2013',
 @DisbNoofOD int='%',
 @DisbRecAssignTo varchar(100)='%'

SELECT     MI.AppID, MI.AppTitle, MI.AppName, MI.AppjointTitle, MI.AppJointAppName, 
               (CASE WHEN MI.AppJointAppName LIKE '' OR  MI.AppJointAppName IS NULL THEN MI.AppTitle + ' ' + MI.AppName ELSE MI.AppTitle + ' ' + MI.AppName + ' & ' + MI.AppjointTitle
               + ' ' + MI.AppJointAppName END) AS ClientNAME, MI.AppSourceBrName, MI.AppSourceCode, MI.AppReqeustAmt, MI.AppLoanType, 
              MI.AppLoanStatus, MI.AppAsignTo, DI.DisbAcSb, DI.DisbAcLoan, DI.DisbAmt, DI.DisbDate, DI.DisbExpDate, 
              DI.DisbEMIDate, DI.DisbNoofOD, DI.DisbRecAssignTo 
      FROM dbo.TblMasterInfo MI LEFT OUTER JOIN dbo.TblDisburseInfo  DI ON MI.AppID = DI.DisbAppID LEFT OUTER JOIN dbo.TblPrePostApproval PPA ON MI.AppID = PPA.Appid                      
      WHERE  (AppName like '%' + @AppName OR AppName like @AppName + '%' OR AppName like '%' + @AppName + '%')
      --AND (MI.AppID =@AppID)
      AND (MI.AppLoanType like @AppLoanType) 
      AND (MI.AppSourceBrName LIKE @AppSourceBrName) 
      AND (MI.AppSourceCode LIKE @AppSourceCode)
      AND (MI.AppLoanStatus like @AppLoanStatus) 
      AND (MI.AppAsignTo like @AppAsignTo) 
      AND (DI.DisbAcSb LIKE @DisbAcSb) 
      --AND (DI.DisbAcLoan LIKE @DisbAcLoan) 
      --AND (DATEADD(s,1,DI.DisbDate) &gt; @DisbDate)  
      --AND (DATEADD(s,-1,DI.DisbDate) &lt; @DisbDate2) 
      --AND (DATEADD(s,1,DI.DisbExpDate) &gt; @DisbExpDate)  
      --AND (DATEADD(s,-1,DI.DisbExpDate) &lt; @DisbExpDate2) 
      --AND (DATEADD(s,1,DI.DisbEMIDate) &gt; @DisbEMIDate)  
      --AND (DATEADD(s,-1,DI.DisbEMIDate) &lt; @DisbEMIDate2) 
      AND (DI.DisbNoofOD = @DisbNoofOD) 
      AND (DI.DisbRecAssignTo LIKE @DisbRecAssignTo)
于 2013-08-29T09:46:00.500 回答