الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

BUG: Syntax Error in INSERT INTO

مغلق
بدأه hazzoom في 3 مارس 2006 · 2 رد · 1,889 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

وأنا أعمل في مشروع ما مرتبط بالأكسس 2003 , ظهر لي الـ Exception التالي في جملة الـ Update الخاصه بالـ OleDb.OleDbDataAdapter :

Syntax Error in INSERT INTO

أنا طبعا استغربت , لأني استخدمت الـ CommandBuilder ولم أستخدم جمل SQL في التعامل مع الـ Database Tables !!! :blink:

المهم أحاول يمين أحاول شمال مفيش فايده رحت غير الـ ConnectionString والـ Providor الي SQLServer وعملت نفس القاعده عليه , ورحت شغلت البرنامج تاني , فكانت المفاجأة ... حيث أنه لم يظهر هذا الـ Exception !!! قلت يبقي العيب مش في الكود ولكن العيب في الـ Access Database !!!

بحثت في الـ Local MSDN ووجدت أن الـ Exception بسبب Bug !!! :blink:

Knowledge Base  

BUG: "Syntax Error in INSERT INTO..." on ADO Recordset.Update
PSS ID Number: 189220

Article Last Modified on 3/2/2005


--------------------------------------------------------------------------------
The information in this article applies to:


Microsoft Data Access Components 1.5
Microsoft Data Access Components 2.0
Microsoft Data Access Components 2.1 SP2
Microsoft Data Access Components 2.5
Microsoft Data Access Components 2.6
Microsoft Data Access Components 2.7
Microsoft ODBC Driver for Access 3.5
Microsoft ODBC Driver for Access 4.0

--------------------------------------------------------------------------------

This article was previously published under Q189220
SYMPTOMS
When you call the AddNew method, and then call the Update method of a Recordset, the following error is returned: 
Microsoft OLE DB Provider for ODBC Drivers error '80040e21'
[Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in INSERT INTO statement. 
Using the Microsoft Access ODBC Driver version4.00.4202.00 or later, the error message is: 
Run-time error '-2147467259(80004005)':
[Microsoft][ODBC Microsoft Access Driver]Syntax error in INSERT INTO statement. 
CAUSE
This error occurs if the following are true: 
The CursorType is adOpenForwardOnly (0).
The CursorLocation is adUseServer.
A field being updated has a space in the field name. 
You are using the Microsoft Access ODBC driver.
Calling the AddNew and Update methods, on a Server-Side, Forward-Only cursor, is an invalid operation. ActiveX Data Objects (ADO) compensates for this code flaw by generating an INSERT statement to perform the operation. When ADO generates the INSERT statement, it does not delimit the field names. Therefore, field names that contain a space generate a syntax error. 

For example, a valid INSERT statement would be as follows: 
   INSERT INTO Table ([field with space]) Values(value)
    
ADO generates the following code: 
   INSERT INTO Table (field with space) Values(value)
    
RESOLUTION
Here are several possible resolutions: 
Do not use spaces in the field names in your database. 
Use a CursorLocation of adUseClient (3). 
Do not use a CursorType of adOpenForwardOnly (0), such as adOpenKeyset (1), adOpenDynamic (2), or adOpenStatic (3). 
Perform the operation by generating your own INSERT statement, with delimiters on the field names, instead of using the AddNew and Update methods.
Use the Microsoft OLE DB Provider for Jet version 3.51 or 4.0 instead of the Microsoft OLE DB Provider for ODBC and the Microsoft Access ODBC Driver.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. 
Keywords: kbbug kbDatabase kbDriver kbJET KB189220 
Technology: kbAccessSearch kbAudDeveloper kbMDAC150 kbMDAC200 kbMDAC210SP2 kbMDAC250 kbMDAC260 kbMDAC270 kbMDACSearch kbODBCAccess350 kbODBCAccess400 kbODBCSearch

فهل صادف أحدكم هذه المشكله قبل ذلك ؟؟؟ وما حلها بغض النظر عن الحلول المطروحه !!! :P

test.rar

تم تعديل هذه المشاركة بواسطة hazzoom في 3 مارس 2006 في 03:08

#2

السلام عليك

بعد التجربة، وجدت أن الاخطاء التي ارتكبتها هي أخطاء بسيطة لكنها مربكة:

الخطأ الاول هو في إدخال قيم الحقول، في المثال الذي أرفقته الحقلين serial و amount هما حقلين رقميين، لا يجب وضع قيمهما بين علامتي تنصيص، فقط الـ strings تحدد بعلامتي تنصيص.

والخطأ الثاني هو في بنية قاعدة البيانات، بالتحديد في الجدول importstb فيجب تجنب استعمال الكلمات المحجوزة (حتى في المتغيرات) كـ name, title, id, date ....

في الجدول importstb يكفي تغيير الحقل date الى import_date فينتهي الاشكال.

بالتوفيق إن شاء الله

#3
اقتباس
الخطأ الاول هو في إدخال قيم الحقول، في المثال الذي أرفقته الحقلين serial و amount هما حقلين رقميين، لا يجب وضع قيمهما بين علامتي تنصيص، فقط الـ strings تحدد بعلامتي تنصيص

في المشروع الأصلي الذي أعمل فيه تعاملت مع الأرقام علي انها أرقام والنص علي انه نص , لكن في المثال الذي وضعته نسيت ذلك لكي لا أضع المشروع طبعا , لذلك ليست هذه هي المشكله ,

اقتباس
والخطأ الثاني هو في بنية قاعدة البيانات، بالتحديد في الجدول importstb فيجب تجنب استعمال الكلمات المحجوزة (حتى في المتغيرات) كـ name, title, id, date ....

نعم اتضح انها هي سبب المشكله (date) , جزاك الله خيرا أخي الفاضل ,

ولكن في SQL Server لا يسبب استخدام هذه الـ Keyword هذه المشكله ,

عالعموم شكرا وكله في السليم ,,,

هذا الموضوع مغلق.

مواضيع مشابهة