如何更新主键(位置编号)所有其他列更新除位置编号外 [英] How Do I Update The Primary Key(Positionnumber)All The Other Columns Get Updated Except Position Number
本文介绍了如何更新主键(位置编号)所有其他列更新除位置编号外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按钮
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
推荐答案
您需要使用两个参数职位编号,旧编号和新编号。包括以下内容:
You would need to use two parameters for te position number, the old one and the new one. COnsider the following:
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 .
原则上,主键永远不会改变,因为值无关紧要。重要的是,每个记录的值都是唯一的,它用作基数之间的链接。
By principle, a primary key should never change because the value does not matter. What matters is that the value is unique to each record and it is used as link between bases.
这篇关于如何更新主键(位置编号)所有其他列更新除位置编号外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文