[英]In visual studio when i trying to add record to ACCESS file :The field is too small to accept the amount of data you attempted to add.
I am trying to add some record to ACCESS file ,as you can see here : 我正在尝试向ACCESS文件添加一些记录,如您在此处看到的:
string strconnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccessTemp.mdb";
private void InsertSellItems(List<TTMSModel> lstttms )
{
try
{
foreach (TTMSModel t in lstttms)
{
if (t.TypeMember == "حقیقی") t.TypeMember = "1";
else
{
t.TypeMember = "2";
}
OleDbConnection objconnection = new OleDbConnection(strconnection);
OleDbCommand objcommand = new OleDbCommand("INSERT INTO Foroush_Detail" +
"(KalaKhadamatName,KalaCode,BargashtType,Price,MaliatArzeshAfzoodeh,AvarezArzeshAfzoodeh,HCKharidarTypeCode,KharidarPostCode,KharidarPerCityCode,KharidarTell,KharidarAddress,KharidarName,KharidarLastNameSherkatName,KharidarEconomicNO,KharidarNationalCode,HCKharidarType1Code,CityCode,stateCode,IsSent,Sarjam)" +
"VALUES('فروش'," +"'0'"+",'0','"+t.PriceAmount+"','"+t.MayorAmount+"','"+t.TaxAmount+"','"+t.TypeMember+"','"+t.ZipCode+"','"+t.City+"','"+t.PhoneNumber+"','"+t.Address+"','"+t.Name+"','"+t.Name+"','"+t.EconomicNumber+"','"+t.IntNumber+"','2','"+t.City+"','"+t.Province+"','0','0')",
objconnection);
objconnection.Open();
objcommand.ExecuteNonQuery();
objconnection.Close();
}
}
catch (OleDbException a)
{
MessageBox.Show(a.Message);
}
}
I fetched the data from SQL server 2012.but after executing this query i got this error: 我从SQL Server 2012中获取了数据。但是执行此查询后,出现了以下错误:
the field is too small to accept the amount of data you attempted to add access 2010.
The table structure is like this : 表结构是这样的:
Best regards 最好的祝福
对于声明为Yes/No
类型的BargashtType
列,您尝试插入فروش
。这是无效的,因为该字段仅接受0或1,即true或false。
It appears to me you are passing ever value in the query as a string, depite the fact some of the fields are numbers: 在我看来,尽管某些字段是数字,但您正在将查询中的值作为字符串传递。
'"+t.City+"','"+t.Province+"'
'“ + t.City +”','“ + t.Province +”'
Both of these values have a single quote around them, meaning they are strings, yet the two fields are Numbers. 这两个值都用单引号引起来,这意味着它们是字符串,而两个字段都是数字。
That means you're leaving Access to do the conversion, you might want to try passing them as numeric values and see if that resolves the problem 这意味着您要离开Access进行转换,您可能想尝试将它们作为数值传递,看看是否可以解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.