2

我有一个页面,其中根据下拉选择动态生成网格视图,

我能够在所需列中生成文本框控件并向其插入数据,并能够在回发/保存按钮单击时在同一文本框中显示数据

我在将值保存到数据库时遇到问题,

我可以使用分隔符将文本框值和在gridview中生成的参数的ID保存到两个字符串变量中

我已经使用拆分函数在存储过程中拆分字符串中的值,我的 SP 执行时没有给出任何错误,但数据库没有使用 sqlhelper 类更新,委托

有人能帮我找出我的错误吗

    ALTER PROCEDURE [dbo].[SP_SaveShpValues]
    @shpVals varchar(max),
    @user varchar(30),
    @qdmt decimal(8,3),
    @qwmt decimal(8,3),
    @moisture decimal(8,3),
    @valwith int,
    @strAnal varchar(30),
    @status int out,
    @vesId int,
    @sDate varchar(50),
    @paramId varchar(max),
    @intAnalysisId int,
    @grade int
AS
declare @varvaltime varchar

开始

set @varvaltime= sysdatetime()
insert into TRAN_SHIPMENT_VALUES (Value,Shp_Parameter_Id,SailDate,Vessel_Id,Analysis_Id,Valuewith,Grade,Last_Updated_By,IsActive,IsDeleted)
select Value.Value, Shp_Parameter_Id.Shp_Parameter_Id,@sDate SailDate , @vesId Vessel_Id ,@intAnalysisId Analysis_Id ,@valwith Valuewith,@grade Grade,@user Last_Updated_By,IsActive=1,IsDeleted=0
from (SELECT  ROW_NUMBER() OVER (ORDER BY (SELECT 0)) RowNo,cast (Item as decimal) Value FROM dbo.SplitString(@shpVals, ',')  ) Value,
     (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) RowNo,Item Shp_Parameter_Id FROM dbo.SplitString( @paramId, ',') ) Shp_Parameter_Id 
where  Shp_Parameter_Id.RowNo=Value.RowNo

END 我尝试将 varchar 转换为十进制,如下所示

块引用

(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) RowNo,cast (Item as decimal) Value FROM dbo.SplitString(@shpVals, ',') ) 值

--IN MY BLL--
public static int SaveShpValues( string shpVals, string user, out int status, int intAnalysisId, int valwith, decimal qdmt, decimal qwmt, decimal moisture, string strDate, string strAnal, int vesId, string paramId, int grade)
   {
       int intStatus = 0;
       intStatus = TestsDLL.SaveShpValues(shpVals, user, out status, intAnalysisId, valwith, qdmt, qwmt, moisture, strDate, strAnal, vesId, paramId, grade);

       return intStatus;
   }

这里 intStatus 在 BLL 中返回 0 我能够将值传递给变量,在调试时我可以看到这些但 intStatus 返回 0

--在我的数据访问层 DLL --

public static int SaveShpValues( string shpVals, string user, out int status, int intAnalysisId, int valwith, decimal qdmt, decimal qwmt, decimal moisture, string strDate, string strAnal, int vesId, string paramId, int grade)
   {
       SqlParameter[] arrParam = null;
       try
       {
           arrParam = new SqlParameter[13];


           arrParam[0] = new SqlParameter("@shpVals", SqlDbType.VarChar);
           arrParam[0].Value = shpVals;

           arrParam[1] = new SqlParameter("@user", SqlDbType.VarChar, 30);
           arrParam[1].Value = user;

           arrParam[2] = new SqlParameter("@qdmt", SqlDbType.Decimal);
           arrParam[2].Value = qdmt;

           arrParam[3] = new SqlParameter("@qwmt", SqlDbType.Decimal);
           arrParam[3].Value = qwmt;

           arrParam[4] = new SqlParameter("@moisture", SqlDbType.Decimal);
           arrParam[4].Value = moisture;

           arrParam[5] = new SqlParameter("@valwith", SqlDbType.Int);
           arrParam[5].Value = valwith;

           arrParam[6] = new SqlParameter("@strAnal", SqlDbType.VarChar);
           arrParam[6].Value = strAnal;

           arrParam[7] = new SqlParameter("@status", SqlDbType.Int);
           arrParam[7].Direction = ParameterDirection.Output;

           arrParam[8] = new SqlParameter("@vesId", SqlDbType.Int);
           arrParam[8].Value = vesId;

           arrParam[9] = new SqlParameter("@strDate", SqlDbType.VarChar);
           arrParam[9].Value =  strDate;

           arrParam[10] = new SqlParameter("@paramId", SqlDbType.VarChar);
           arrParam[10].Value = paramId;

           arrParam[11] = new SqlParameter("@intAnalysisId", SqlDbType.Int);
           arrParam[11].Value = intAnalysisId;

           arrParam[12] = new SqlParameter("@grade", SqlDbType.Int);
           arrParam[12].Value = grade;


           SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "SP_SaveShpValues", arrParam);

           if (arrParam[7].Value != DBNull.Value) // status
               status = Convert.ToInt32(arrParam[7].Value);
           else
               status = 0;
           return status;
       }
       catch (Exception objEx)
       {
           ErrorLogDAL objErrorLogManager = new ErrorLogDAL();
           objErrorLogManager.AddErrorLog(objEx);
           objErrorLogManager = null;

           status = 0; return status;
       }
       finally
       {
           arrParam = null;
       }
   }

-- 在代码后面-

public void Saveval(string AnalysisName)
   {
       int vesId = Convert.ToInt32(ddlVesselList.SelectedValue);
       DateTime.TryParseExact(txtsaildate.Text.ToString(), "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out saildt);
       string strDate = saildt.Date.ToString("MM-dd-yyyy");

       decimal qdmt = Decimal.Parse(lblDMTvalue.Text);
       decimal qwmt = Decimal.Parse(txtwmt.Text);
       decimal moist = Decimal.Parse(txtmoist.Text);
       int status = 0;
       int valid = 1;
       SaveShipValues_delegate del = null;
       int analysis_Id = Convert.ToInt32(ddlanalysis.SelectedValue);
       selction = Convert.ToInt32(ddlvalueswith.SelectedValue);

       DataTable dtparam = TestsBLL.GetParamtoTable(analysis_Id, selction);
       foreach (DataRow drparam in dtparam.Rows)
       {
           paramId = Convert.ToInt32(drparam["Parameter_Id"]) + "," + paramId;
       }
       try
       {
           pIndx = 0;
           if (AnalysisName == "xxx")
           {
               foreach (GridViewRow gr in gridshipval.Rows)
               {
                   TextBox txtbox = (TextBox)gr.FindControl("txtbox'"+pIndx+"'");
                   if (txtbox != null)
                   {
                       string strRegExp = "^([0-9]{1,25})?(.[0-9]{0,8})?$";
                       txtbox.CausesValidation = true;
                       txtbox.MaxLength = 6;
                       if (System.Text.RegularExpressions.Regex.IsMatch(txtbox.Text, strRegExp))
                       {

                           shpVals = txtbox.Text + "," + shpVals;
                           pIndx++;
                       }
                       else
                       {
                           txtbox.BorderColor = System.Drawing.Color.Red;
                           lblMsg.Text = "Please give only numbers";
                           shpVals = "";
                           valid = 0;
                           break;
                       }

                   }
                   else break;
               }
           }

否则 if (AnalysisName == "yyy") ----

string strAnal = ddlanalysis.SelectedItem.ToString();
               int grade = Convert.ToInt32(ddlgrade.SelectedValue);

               del = new SaveShipValues_delegate(TestsBLL.SaveShipValues);
               IAsyncResult res = null;
               res = del.BeginInvoke(shpVals, Convert.ToString(Session["UserName"]), out status, Convert.ToInt32(ddlanalysis.SelectedValue), Convert.ToInt32(ddlvalueswith.SelectedValue), qdmt, qwmt, moist, strDate, strAnal, vesId,  paramId,grade, null, null);
               lblMsg.Text = "Values Saved Successfully, Please check updated values after 2 minutes.";

有人可以帮助找到并纠正我的错误吗

4

0 回答 0