2011-01-21 69 views
0

我有一个数据库表,所有列允许空值用于测试目的。在我所有的列之间,我有int,varchar或bit数据类型。当我尝试提交表单,我得到了以下错误消息:帮助LINQ到SQL插入错误

Value was either too large or too small for an Int32. 

下面是代码:

using (storeDataContext db = new storeDataContext()) 
     { 

      db.Dealerssses.InsertOnSubmit(new Dealersss 
      { 
       AppFName = txtFName.Text, 
       AppLName = txtLName.Text, 
       AppTitle = ddlTitles.SelectedItem.Text, 
       AppPhone = Convert.ToInt32(txtPhone.Text), 
       AppEmail = txtEmail.Text, 
       AppAddress = txtAddress.Text, 
       AppCity = txtCity.Text, 
       AppState = txtState.Text, 
       AppZip = Convert.ToInt32(txtZip.Text), 
       BusName = txtBusName.Text, 
       BusCA = Convert.ToInt32(txtBusResale.Text), 
       BusContact = txtBusContact.Text, 
       BusDBA = txtDBA.Text, 
       BusEIN = Convert.ToInt32(txtBusEIN.Text), 
       BusEmail = txtBusEmail.Text, 
       BusFax = Convert.ToInt32(txtBusFax.Text), 
       BusMonth = ddlMonthStart.SelectedItem.Text, 
       BusNumEmployees = Convert.ToInt32(txtBusEmployees.Text), 
       BusPhone = Convert.ToInt32(txtBusPhone.Text), 
       BusYear = int.Parse(txtYearStart.Text), 
       Active = false 
      }); 
      db.SubmitChanges(); 
     }; 
+0

您是否看过错误? – SLaks 2011-01-21 03:35:42

+0

@slaks,表单中发布的值在1到15位之间,因此int32的值不可能太大。 – 2011-01-21 03:37:16

回答

2

Int32.MaxValue2,147,483,647,这是只有10位。
对于Int32,您的值为太大。

您的电话,传真,ZIP和EIN字段应该是字符串(NVARCHAR),而不是数字。

1

我敢打赌这是你电话号码字段的值。 Int32是一个4字节的整数,最大值为2147483647.大多数电话号码都会溢出。

1

我的猜测是,它是在你的手机#的的Int32的具有值:

2,147,483,648 2,147,483,647

所以,如果你有517111111(5171111111)的电话号码,你是太大。

你应该使用varchar/char作为电话号码。