在参数子句中使用的MS Access querydefs通过参数为十进制类型路过时,语法错误 [英] Syntax error in PARAMETER clause when passing through parameters as Decimal types using MS Access querydefs

查看:642
本文介绍了在参数子句中使用的MS Access querydefs通过参数为十进制类型路过时,语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个插入查询需要的财务数据,并从.NET

I'm trying to write an insert query that takes financial data and writes it to my Access database from .net

现在的问题是,我不能经由十进制数据类型的参数,我的数据传递,尽管能够选择他们作为在MS接入十进制数据类型参数窗口,尽管该数据库能够创建十进制数据类型的表中的字段。

The problem is that I cannot pass through my data via decimal datatype parameters despite being able to select them as Decimal datatype in the Ms Access parameters window, and despite the database being able to create table fields of Decimal datatype.

我在想,是什么,我试图做可能吗?如果是的话怎么样?

I was wondering, is what I am trying to do possible? If so how?

下面是我查询的款:

PARAMETERS pMidPrice Decimal;
INSERT INTO NonStandardPricingInstructions ( MidPrice)
SELECT pMidPrice as Expr1

如果我改变十进制转​​换为IEEEDouble那么它的工作原理,但我会preFER通过一个小数如果可能的话。

If I change Decimal to IEEEDouble then it works, but I would prefer to pass through a Decimal if possible.

感谢

推荐答案

以下似乎为我工作:

有关在访问已保存的查询名为[qryDecimalTest]:

For a saved query in Access named [qryDecimalTest]:

PARAMETERS pDecimalColValue Decimal;
SELECT Clients.ID
FROM Clients
WHERE (((Clients.decimalCol)=[pDecimalColValue]));

下面的C#code发现的记录,其中十进制字段为3,并返回正确的ID值

the following C# code finds the record where the Decimal field is 3 and returns the correct ID value

cmd.CommandText =
    "SELECT ID FROM qryDecimalTest";
decimal queryParameterValue = 3;
cmd.Parameters.Add("?", OleDbType.Decimal).Value = queryParameterValue;
var thing = cmd.ExecuteScalar();
Console.WriteLine(String.Format("{0} ({1})", thing, thing.GetType().ToString()));

编辑回复:评论

我尝试另一个测试,但这次我用Jet.OLEDB对一个Access 2000 .mdb文件。我在访问改变了保存查询

Edit re: comments

I tried another test, but this time I used Jet.OLEDB against an Access 2000 .mdb file. I changed the saved query in Access to

PARAMETERS pMidPrice Decimal;
INSERT INTO NonStandardPricingInstructions ( MidPrice )
SELECT [pMidPrice] AS Expr1;

和使用下面的C#code

and used the following C# code

cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText =
    "qryDecimalTest";
decimal queryParameterValue = 3;
cmd.Parameters.Add("?", OleDbType.Decimal).Value = queryParameterValue;
cmd.ExecuteNonQuery();

这工作得很好了。

这篇关于在参数子句中使用的MS Access querydefs通过参数为十进制类型路过时,语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆