使用 C# 将查询插入 Paradox 表时出现问题
我需要连接 Paradox 5.x 表才能进行选择和更新。 我正在使用 OLEDBConnection。
从表中选择我没有问题。 在尝试插入表时,我遇到了一个问题,当我输入硬编码的字段名称时,出现错误: INSERT INTO 语句包含以下未知字段名称:... 所以我使用 OleDbDataReader.GetName(...) 来获取字段名称。 现在我使用从表接收的字段名称来插入表中,但仍然遇到相同的错误。
我认为问题在于字段名称:“卡车 #1 序列号” 表名称:“车辆”
我尝试使用 []、.""、.[] 和 .[“”]。
我读过有关 Borland 引擎的需求,但我不确定这就是问题所在。 预先感谢。
-=Noam=-
ps 我无法更改表的名称,因为它是我需要连接的客户数据库。
我添加我使用的 C# 代码:
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;
}
在结束试用时保持:
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','')
编辑: 只是想在最后添加我的解决方案: 最后,我能得到的最好的解决方案是使用访问作为连接点,使用链接表到悖论表,最后将其作为访问数据库处理...... 希望它能帮助某人。
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 names I 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 received 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 I'm not sure this is the issue.
Thanks upfront.
-=Noam=-
p.s I cannot change name of tables since its a customer 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 tables to the paradox tables, at end handling it as an accesses DB.....
Hope it helps someone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当字段或表名称中包含特殊字符时,您需要使用带引号的标识符。双引号 (
"
) 应该就是您要查找的内容。此外,我确实相信需要 Borland 数据库引擎才能针对 Paradox 等 Borland 数据库工作。至少,这就是我一直被告知的,尽管我从未体验过这样的架构,因为我在使用 Paradox 时使用了 Delphi。
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.
当你找到一个(有点复杂的)解决方案时......
可能值得进行 ODBC 跟踪并查看 Access 如何传递导致问题的字段名称。它可能只是 paradox 接受的哈希 (#) 或类似内容的转义序列。只是一个想法。
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.
我能够通过创建一个带有数字符号(col#)的列的表(Table1)来重现该问题。例如:
在我运行此 SQL 的地方,我收到此错误:
这似乎是 Microsoft JET 提供程序的错误。找到的唯一解决方法是将值插入到另一列中
,然后更新 col# 列:
我发现 JET 提供程序存在其他问题。例如,如果表没有主键或密码保护,您将收到此错误:
I was able to reproduce the problem by creating a table (Table1) with a column that has number sign (col#). Like:
Where I run this SQL I get this Error:
This seems to be a bug Microsoft JET provider. The only workaround is found is to insert the value into another column like
And then update the col# column:
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: