Problem with Insert query to Paradox table using C#

只谈情不闲聊 提交于 2019-12-10 03:49:19

问题


I have Paradox 5.x tables i need to connect to in order to select and update. I am using OLEDBConnection.

selecting from the tables i have no problem. while trying to insert into the tables i met a problem when i entered hardcoded the fields namesi got an error: The INSERT INTO statement contains the following unknown field name: ... so i used OleDbDataReader.GetName(...) to get fields names. now i use the fields names recived from table in order to insert into table and i still get the same error.

I think the problem is with the field name: 'Truck #1 Serial Number' Table name: 'Vehicles'

I tried using [], ."", .[] and .[""].

I have read about the need of Borland engine but im not sure this is the issue. Thanks upfront.

-=Noam=-

p.s I cannot change name of tables since its a castumer DB i need to connect.

Im adding the C# code i use:

private static string createInsertQueryVehicle(string i_VehicleNumber, string i_VehicleMFG, string i_Truck1SerialNo, string i_Truck2SerialNo, string i_Truck3SerialNo)
        {
            string tryout = string.Format("INSERT INTO {0} ([{6}], [{7}], [{8}], [{9}], [{10}]) VALUES(RIGHT('{1}',10),'{2}','{3}','{4}','{5}')",
                TableName, Vnum, Vinfo, T1Serial, T2Serial, T3Serial, VnumFieldName, VinfoFieldName, T1SerialFieldName
                T2SerialFieldName,T3SerialFieldName);
            return tryout;
        }

at end tryout holds:

INSERT INTO Vehicles ([Vehicle Number], [Vehicle Mfg], [Truck #1 Serial Number], [Truck #2 Serial Number], [Truck #3 Serial Number]) VALUES(RIGHT('000000010001525',10),'קרונות משא','ר40011_1','ר40011_2','')

EDIT: Just wanted to add my solution at end: At the end the best solution i could get was to use accesses as the connection point using linked tablse to the paradox tables, at end handling it as an acceses DB..... Hope it helps someone.


回答1:


You need to use the quoted identifiers while having special character in field or table names. The double-quote (") should be what you're looking for.

Besides, I do believe that the Borland Database Engine is required in order to work against a Borland database such as Paradox. At least, that what I have always been told to, though I have never yet experienced such architecture, since I was using Delphi when working with Paradox.




回答2:


As you founda (somewhat convoluted) solution... Might be worth putting an ODBC trace on and seeing how Access is passing the field name that's causing the issue. It may just be an escape sequence that paradox accepts for the hash (#) or something similar. Just a thought.




回答3:


I was able to reproduce the problem by creating a table (Table1) with a column that has number sign (col#). Like:

INSERT INTO `Table1.db` (`col#`) VALUES ('a')

Where I run this SQL I get this Error:

The INSERT INTO statement contains the following unknown field name: 'col#'.  Make sure you have typed the name correctly, and try the operation again.

This seems to be a bug Microsoft JET provider. The only workaround is found is to insert the value into another column like

INSERT INTO `Table1.db` (`col1`) VALUES ('a')

And then update the col# column:

UPDATE `Table1.db` SET `col#` = col1

I found other problems with the JET provider. For example, you will get this wrong error if the table is does not have a primary key or password protected:

Operation must use an updateable query.


来源:https://stackoverflow.com/questions/4366988/problem-with-insert-query-to-paradox-table-using-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!