我已经解决了这个问题,但无法弄清楚为什么我的更新失败了。我对 SQL 不感兴趣。我写了一个简单的存储过程。
这是代码:
CREATE PROCEDURE [dbo].sp_UpdateTeamMemberProfile
@TeamMemberId int OUTPUT,
@FirstName varchar(25),
@LastName varchar(30),
@ContactNumber varchar (20),
@ContactExt varchar (20) ,
@EmailAddress varchar(100),
@Fax varchar (25),
@LocationCity varchar (20),
@LocationState varchar (20),
@BeginWorkHrs int,
@BeginWorkTime varchar (20) ,
@EndWorkHrs int ,
@EndWorkTime varchar (20) ,
@ZONE Varchar (20),
@TeamMemberLanId varchar (20),
@ManagerId varchar (20),
@UpdateDate datetime
AS
BEGIN
SET NOCOUNT ON;
BEGIN
UPDATE dbo.LoanOwnerStamp
SET FirstName = @FirstName,
LastName = @LastName,
ContactNumber = @ContactNumber,
ContactExt = @ContactExt ,
EmailAddress = @EmailAddress,
Fax = @Fax,
LocationCity = @LocationCity,
LocationState = @LocationState,
BeginWorkHrs = @BeginWorkHrs,
BeginWorkTime = @BeginWorkTime,
EndWorkHrs = @EndWorkHrs,
EndWorkTime = @EndWorkTime,
Zone = @Zone,
TeamMemberLanId = @TeamMemberLanId,
ManagerId = @ManagerId ,
UpdatedDate = @UpdateDate
WHERE
TeamMemberLanId = @TeamMemberLanId
AND TeamMemberId = @TeamMemberId
END
SET @TeamMemberId = SCOPE_IDENTITY()
RETURN @TeamMemberId
END
现在后面的代码如下...
using (SqlCommand updatetLSTeamMember = new SqlCommand("sp_UpdateTeamMemberProfile", myConnection))
{
updatetLSTeamMember.CommandType = CommandType.StoredProcedure;
updatetLSTeamMember.Parameters.Add("@FirstName", SqlDbType.VarChar, 25).Value = txtFirstName.Text;
updatetLSTeamMember.Parameters.Add("@LastName", SqlDbType.VarChar, 30).Value = txtLastName.Text;
updatetLSTeamMember.Parameters.Add("@ContactNumber", SqlDbType.VarChar, 20).Value = txtContactNumber.Text;
updatetLSTeamMember.Parameters.Add("@ContactExt", SqlDbType.VarChar, 20).Value = txtContactExt.Text;
updatetLSTeamMember.Parameters.Add("@EmailAddress", SqlDbType.VarChar, 100).Value = txtEmailAddress.Text;
updatetLSTeamMember.Parameters.Add("@Fax", SqlDbType.VarChar, 25).Value = txtFax.Text;
updatetLSTeamMember.Parameters.Add("@LocationCity", SqlDbType.VarChar, 20).Value = txtLocationCity.Text;
updatetLSTeamMember.Parameters.Add("@LocationState", SqlDbType.VarChar, 20).Value = txtState.Text;
updatetLSTeamMember.Parameters.Add("@BeginWorkHrs", SqlDbType.Int).Value = ddlBeginHrs.SelectedValue.ToString();
updatetLSTeamMember.Parameters.Add("@BeginWorkTime", SqlDbType.VarChar, 20).Value = ddlBeginTime.SelectedValue.ToString();
updatetLSTeamMember.Parameters.Add("@EndWorkHrs", SqlDbType.Int).Value = ddlEndHrs.SelectedValue.ToString();
updatetLSTeamMember.Parameters.Add("@EndWorkTime", SqlDbType.VarChar, 20).Value = ddlEndTime.SelectedValue.ToString();
updatetLSTeamMember.Parameters.Add("@Zone", SqlDbType.VarChar, 20).Value = ddlZone.SelectedItem.Text;
updatetLSTeamMember.Parameters.Add("@TeamMemberLanId", SqlDbType.VarChar, 20).Value = txtTeamMemberLaniId.Text;
updatetLSTeamMember.Parameters.Add("@ManagerId", SqlDbType.VarChar, 20).Value = gblUserId;
updatetLSTeamMember.Parameters.Add("@UpdateDate", SqlDbType.DateTime).Value = DateTime.Now.ToLocalTime();
pID = updatetLSTeamMember.Parameters.Add("@TeamMemberId", SqlDbType.Int); // I'm thinking this is a culprit
pID.Direction = ParameterDirection.Output; // are these assignment correct.
try
{
if (updatetLSTeamMember.Connection.State == ConnectionState.Closed)
{
updatetLSTeamMember.Connection.Open();
}
updatetLSTeamMember.ExecuteNonQuery(); // code bombs out here
string idcat = updatetLSTeamMember.Parameters["@TeamMemberId"].Value.ToString();
现在我的问题在几个地方,我的Parameter.Direction
输出是否正确,从存储过程的角度来看是否正确?
任何帮助表示赞赏。