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メッセージが表示されますが、レコードは更新されません。私の問題はどこにあるのか、特定できません。Pls は私をサポートします。

ありがとう

4

2 に答える 2

0

問題は、INwhere UserBrDiv in(@ParmUserBrDiv)がそのように機能しないため、実際にはレコードが選択されないことです。これを 2 つの異なる場所で使用し、 を取得します@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 に答える