本文介绍了如何更新主键(位置编号)所有其他列更新除位置编号外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按钮

Button

Business_Logic.Employee objpo = new Business_Logic.Employee();
   objpo.Position_Number = TxtPositionNum.Text;
   objpo.Grade = TxtGrade.Text;
   objpo.StartDate = Txtstartda.Text;

   objpo.UpdatePosition(LblPositNum.Text);



Business Logic


Business Logic

     public void UpdatePosition(string Position_Number)
       {

                    csDAL objdal = new csDAL();
           List<csparameterlisttype>objl = new List<csparameterlisttype>();
          
 objl.Add(new csParameterListType("@Position_Number", SqlDbType.VarChar, Position_Number));
           
objl.Add(new csParameterListType("@Grade", SqlDbType.VarChar, Grade));
           
objl.Add(new csParameterListType("@StartDate", SqlDbType.VarChar, StartDate));
                  
  objdal.executespreturnds("Update_Position", objl);
       }



SQL


SQL

Create procedure [dbo].[Update_Position]
(@Position_Number char(15),
@Grade varchar(5),
@StartDate varchar(1000)
)
as update PositionInformation set Position_Number=@Position_Number,Grade = @Grade,StartDate =@StartDate 
where Position_Number=@Position_Number

推荐答案

Create procedure [dbo].[Update_Position]
(@Position_Number_old char(15),
@Position_Number_new char(15),
@Grade varchar(5),
@StartDate varchar(1000)
)
as 
update PositionInformation 
set Position_Number=@Position_Number_new,
    Grade = @Grade,
    StartDate =@StartDate 
where Position_Number=@Position_Number_old



但在跳转之前,在我看来,你应该真正修改参数类型和列类型相应。切勿在字符类型中存储日期或数字。而是使用正确的类型,如date,int,float。


But before jumping to that, in my opinion, you should really modify the parameter types and column types correspondingly. Never store dates or number in character types. Instead use proper types such as date, int, float .



这篇关于如何更新主键(位置编号)所有其他列更新除位置编号外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 07:06