更新数据时出错
Error converting data type nvarchar to int.
我的代码是
public bool UpdateData(MemberInfo memberinfo)
{
SqlCommand cmd = DataConnection.GetConnection().CreateCommand();
cmd.CommandText = "prcUpdateMemberInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@MemberFirstName", memberinfo.MemberFirstName));
cmd.Parameters.Add(new SqlParameter("@MemberMiddleName", memberinfo.MemberMiddleName));
cmd.Parameters.Add(new SqlParameter("@MemberLastName", memberinfo.MemberLastName));
cmd.Parameters.Add(new SqlParameter("@FatherName", memberinfo.FatherName));
cmd.Parameters.Add(new SqlParameter("@MotherName", memberinfo.MotherName));
cmd.Parameters.Add(new SqlParameter("@FamilyHeadName", memberinfo.FamilyHeadName));
cmd.Parameters.Add(new SqlParameter("@DOB", memberinfo.DOB));
cmd.Parameters.Add(new SqlParameter("@EducationLevelID", memberinfo.EducationLevelID));
cmd.Parameters.Add(new SqlParameter("@EducationFieldID", memberinfo.EducationFieldID));
cmd.Parameters.Add(new SqlParameter("@BloodGroupID", memberinfo.BloodGroupID));
cmd.Parameters.Add(new SqlParameter("@OccupationTypeID", memberinfo.OccupationTypeID));
cmd.Parameters.Add(new SqlParameter("@Gender", memberinfo.Gender));
cmd.Parameters.Add(new SqlParameter("@GotraID", memberinfo.GotraID));
cmd.Parameters.Add(new SqlParameter("@SectID", memberinfo.SectID));
cmd.Parameters.Add(new SqlParameter("@MaritalStatus", memberinfo.MarritalStatus));
cmd.Parameters.Add(new SqlParameter("@HouseNumber", memberinfo.HouseNumber));
cmd.Parameters.Add(new SqlParameter("@StreetName", memberinfo.StreetName));
cmd.Parameters.Add(new SqlParameter("@Area", memberinfo.Area));
cmd.Parameters.Add(new SqlParameter("@LandMark", memberinfo.LandMark));
cmd.Parameters.Add(new SqlParameter("@StateID", memberinfo.StateID));
cmd.Parameters.Add(new SqlParameter("@CountryID", memberinfo.CountryID));
cmd.Parameters.Add(new SqlParameter("@CityID", memberinfo.CityID));
cmd.Parameters.Add(new SqlParameter("@EmailAddress", memberinfo.EmailAddress));
cmd.Parameters.Add(new SqlParameter("@PhoneNumber", memberinfo.PhoneNumber));
cmd.Parameters.Add(new SqlParameter("@UserId", memberinfo.UserId));
cmd.Parameters.Add(new SqlParameter("@IsSubmit", memberinfo.IsSubmit));
bool ans = cmd.ExecuteNonQuery() > 0;
cmd.Dispose();
DataConnection.CloseConnection();
return ans;
,程序是
create proc [dbo].[prcUpdateMemberInfo]
(
@UserId uniqueidentifier,
@MemberFirstName varchar(20),
@MemberMiddleName varchar(20),
@MemberLastName varchar(20),
@FamilyHeadName varchar(50),
@FatherName varchar(50),
@MotherName varchar(50),
@DOB datetime,
@GotraID int,
@SectID int,
@BloodGroupID int,
@EducationLevelID int,
@EducationFieldID int,
@HouseNumber varchar(20),
@StreetName varchar(50),
@Area varchar(50),
@LandMark varchar(50),
@StateID int,
@CountryID int,
@CityID int,
@PhoneNumber int,
@EmailAddress varchar(50),
@MaritalStatus varchar(20),
@OccupationTypeID int,
@Gender varchar(10),
@IsSubmit bit
)
as
update MemberInfo
set
MemberFirstName = @MemberFirstName,
MemberMiddleName=@MemberMiddleName ,
MemberLastName =@MemberLastName,
FamilyHeadName =@MemberLastName,
FatherName =@FatherName,
MotherName =@MotherName,
DOB =@DOB,
GotraID =@GotraID,
SectID =@SectID,
BloodGroupID =@BloodGroupID,
EducationLevelID =@EducationLevelID,
EducationFieldID =@EducationFieldID,
HouseNumber =@HouseNumber,
StreetName =@StreetName,
Area =@Area,
LandMark =@LandMark,
StateID =@StateID,
CountryID=@CountryID,
CityID =@CityID,
PhoneNumber =@PhoneNumber,
EmailAddress =@EmailAddress,
MaritalStatus =@MaritalStatus,
OccupationTypeID=@OccupationTypeID,
Gender=@Gender,
IsSubmit=@IsSubmit
where UserId =@UserId
班级是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace JaiJinendera.Common
{
public class MemberInfo
{
string memberFirstName, memberMiddleName, memberLastName, fatherName, motherName, familyHeadName, gender, marritalStatus,phoneNumber, houseNumber, landMark, area, streetName, emailAddress;
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public string StreetName
{
get { return streetName; }
set { streetName = value; }
}
public string Area
{
get { return area; }
set { area = value; }
}
public string LandMark
{
get { return landMark; }
set { landMark = value; }
}
public string HouseNumber
{
get { return houseNumber; }
set { houseNumber = value; }
}
public string MarritalStatus
{
get { return marritalStatus; }
set { marritalStatus = value; }
}
public string Gender
{
get { return gender; }
set { gender = value; }
}
public string FamilyHeadName
{
get { return familyHeadName; }
set { familyHeadName = value; }
}
public string MotherName
{
get { return motherName; }
set { motherName = value; }
}
public string FatherName
{
get { return fatherName; }
set { fatherName = value; }
}
public string MemberLastName
{
get { return memberLastName; }
set { memberLastName = value; }
}
public string MemberMiddleName
{
get { return memberMiddleName; }
set { memberMiddleName = value; }
}
public string MemberFirstName
{
get { return memberFirstName; }
set { memberFirstName = value; }
}
int countryID, stateID, cityID, sectID, gotraID, educationLevelID, educationFieldID, bloodGroupID, occupationTypeID;
public int OccupationTypeID
{
get { return occupationTypeID; }
set { occupationTypeID = value; }
}
public string PhoneNumber
{
get { return phoneNumber; }
set { phoneNumber = value; }
}
public int BloodGroupID
{
get { return bloodGroupID; }
set { bloodGroupID = value; }
}
public int EducationFieldID
{
get { return educationFieldID; }
set { educationFieldID = value; }
}
public int EducationLevelID
{
get { return educationLevelID; }
set { educationLevelID = value; }
}
public int GotraID
{
get { return gotraID; }
set { gotraID = value; }
}
public int SectID
{
get { return sectID; }
set { sectID = value; }
}
public int CityID
{
get { return cityID; }
set { cityID = value; }
}
public int StateID
{
get { return stateID; }
set { stateID = value; }
}
public int CountryID
{
get { return countryID; }
set { countryID = value; }
}
DateTime dOB, insertionDate;
public DateTime InsertionDate
{
get { return insertionDate; }
set { insertionDate = value; }
}
public DateTime DOB
{
get { return dOB; }
set { dOB = value; }
}
Guid userId;
public Guid UserId
{
get { return userId; }
set { userId = value; }
}
bool isSubmit;
public bool IsSubmit
{
get { return isSubmit; }
set { isSubmit = value; }
}
}
}
答案 0 :(得分:1)
正如我在评论中所说,在类定义中,PhoneNumber是一个字符串,但存储过程需要一个整数。这是你的问题。
我会将存储过程和基础数据表更改为VARCHAR(30)或类似大小,因为可以使用带字母字符的电话号码。否则,如果您完全确定相反,则将类声明更改为整数。
答案 1 :(得分:0)
您的程序@PhoneNumber int
应该是@PhoneNumber varchar(50)
或其他一些varchar长度。