问题描述
亲爱的所有人,
我使用实体框架数据库的第一个概念。
当我插入通过我的网页将值输入数据库然后发生此异常.-
{字符串或二进制数据将被截断。\\\\ n语句已被终止。 }
请帮忙解决这个问题。
我的数据库表 -
CREATE TABLE [dbo]。[办公室](
[OfficeId] [uniqueidentifier] NOT NULL,
[名称] [varchar ](100)NOT NULL,
[街道] [varchar](100)NOT NULL,
[城市] [varchar](75)NOT NULL,
[状态] [varchar](2)NOT NULL,
[Zip] [varchar](5)NOT NULL,
[电话] [varchar ](9)NOT NULL,
[传真] [varchar](9)NULL,
[CreatedDate] [datetime] NOT NULL,
[IsActive] [bit] NOT NULL,
CONSTRAINT [PK_Office_1] PRIMARY KEY CLUSTERED
(
[OfficeId] ASC
)WITH(PAD_INDEX = OFF,STATISTICS_NORECOMPUTE = OFF,IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS = ON,ALLOW_PAGE_LOCKS = ON)ON [PRIMARY]
)
我的班级档案method-
Dear All,
I am using entity framework database first concept.
when i insert values into database through my web page then this exception occurred.-
{"String or binary data would be truncated.\r\nThe statement has been terminated."}
Please help to solve this.
My database table-
CREATE TABLE [dbo].[Office](
[OfficeId] [uniqueidentifier] NOT NULL,
[Name] [varchar](100) NOT NULL,
[Street] [varchar](100) NOT NULL,
[City] [varchar](75) NOT NULL,
[State] [varchar](2) NOT NULL,
[Zip] [varchar](5) NOT NULL,
[Phone] [varchar](9) NOT NULL,
[Fax] [varchar](9) NULL,
[CreatedDate] [datetime] NOT NULL,
[IsActive] [bit] NOT NULL,
CONSTRAINT [PK_Office_1] PRIMARY KEY CLUSTERED
(
[OfficeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)
my class file method-
public void AddOffice(string OfficeName, string StreetName, string CityName, String StateName, String ZipNumber, String PhoneNumber, string FaxNumber,DateTime CreatedOfficeDate,string IsActiveOffice)
{
try
{
Office ObjOffice = new Office
{
Name = OfficeName,
Street = StreetName,
City = CityName,
State = StreetName,
Zip = ZipNumber,
Phone = PhoneNumber,
Fax = FaxNumber,
CreatedDate=CreatedOfficeDate,
IsActive=bool.Parse(IsActiveOffice.ToString().Trim())
};
tde.AddToOffices(ObjOffice);
tde.SaveChanges();
//tde.AcceptAllChanges();
}
catch (Exception ex)
{
Console.Write(ex);
}
}
守则代码 -
method-
Code behind code-
method-
private void InsertOffice (string OfficeName, string StreetName, string CityName, String StateName, String ZipNumber, String PhoneNumber, string FaxNumber,DateTime CreatedOfficeDate,string OfficeIsActive)
{
UserManager userMgr = new UserManager();
oUserManager.AddOffice( OfficeName, StreetName, CityName, StateName, ZipNumber, PhoneNumber, FaxNumber, CreatedOfficeDate,OfficeIsActive);
}
并从以下方法调用此方法 -
and call this method from following method-
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string OfficeCreatedDate=System.DateTime.Now.ToString();
string Active = "true";
//Boolean IsActive = Convert.ToBoolean(Active.ToString().Trim());
// Int32 IsActive = 1;
InsertOffice(tbOfficeName.Text.ToString().Trim(), tbStreet.Text.ToString().Trim(), tbCity.Text.ToString().Trim(), tbState.Text.ToString().Trim(), tbZip.Text.ToString().Trim(), tbPhone.Text.ToString().Trim(), tbFax.Text.ToString().Trim(), Convert.ToDateTime(OfficeCreatedDate), Active);
lblMsg.Visible = true;
lblMsg.Text = "Office Created Sucessfully";
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = ex.Message;
}
}
谢谢
Mukesh Bhagat。
Thanks
Mukesh Bhagat.
推荐答案
这篇关于发生异常 - {“字符串或二进制数据将被截断。\\\\ n语句已被终止。”}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!