I am trying to add some record to ACCESS file ,as you can see here :

 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:

the field is too small to accept the amount of data you attempted to add access 2010.

The table structure is like this :

enter image description here

Best regards

2

There are 2 best solutions below

0
On

For BargashtType column that is declared as Yes/No type, you are trying to insert فروش .Which is invalid, as the field will accept only 0 or 1 i.e. true or false.

0
On

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+"'

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