将动态gridview文本框值和选择值保存到3层体系结构中的数据库

时间:2018-07-13 07:39:00

标签: c# sql asp.net sql-server-2012 data-controls

我有一个页面,其中根据下拉选择动态生成gridview,

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

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

我能够使用,分隔符将文本框值以及在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转换为十进制,如下所示:

  

Blockquote

(SELECT ROW_NUMBER()OVER(ORDER BY(SELECT 0))RowNo,cast(项目为十进制)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;
               }
           }

否则,如果(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.";

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

0 个答案:

没有答案