简体   繁体   English

在Visual Studio中,当我尝试将记录添加到访问文件时:该字段太小,无法接受您尝试添加的数据量。

[英]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.

相关问题 错误-该字段太小,无法接受您尝试添加的数据量。 尝试插入或粘贴较少的数据 - Error - The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data OledbException-字段太小,无法接受数据量 - OledbException - Field too small to accept amount of data 我尝试添加文件时Visual Studio冻结 - Visual Studio Freezes when I try to Add a file 在Visual Studio 2012中,何时添加ADO.NET实体数据模型(* .edmx)? - In Visual Studio 2012, when you add an ADO.NET Entity Data Model (*.edmx)? package中添加图片资源并部署到Visual Studio中时,图片资源的文件路径是什么? - What is the file path for image resources when you add them during package and deploy in Visual Studio? 尝试添加我的控件时,Visual Studio提供了NullReferenceException! - Visual Studio gives a NullReferenceException when trying to add my control! 尝试在Visual Studio 2010中的表中添加是/否数据类型字段 - Attempting to add a Yes/No data type Field in table in Visual Studio 2010 如何在需要MDW文件时将Access DB添加到我的C#项目中? - How can I add an Access DB to my C# project when it requires an MDW file too? C#需要在触摸记录时向字段添加数据 - C# need to add data to a field when a record is touched BDD Visual Studio 2015有时,当我添加新项目时,我看不到SpecFlow功能文件 - BDD Visual Studio 2015 sometimes when I add new item I cannot see SpecFlow Feature File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM