我正在尝试向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);
}
}
我从SQL server 2012获取数据。但是在执行此查询后,我收到了此错误:
the field is too small to accept the amount of data you attempted to add access 2010.
表结构如下:
祝你好运
答案 0 :(得分:0)
对于声明为BargashtType
类型的Yes/No
列,您尝试插入فروش
。这是无效的,因为该字段只接受0或1,即true或false。
答案 1 :(得分:0)
在我看来,你将查询中的值作为字符串传递,表明某些字段是数字:
' “+ t.City +”', ' “+ t.Province +”'
这两个值都有一个单引号,这意味着它们是字符串,但这两个字段是数字。
这意味着你要离开Access进行转换,你可能想尝试将它们作为数值传递,看看是否能解决问题