使用C#在ACCESS 2010中的数字字段的条件表达式中的数据类型不匹配

时间:2018-02-07 03:21:34

标签: c# ms-access-2010 windows-forms-designer

我跟随两个表及其字段:

invoice - invcID (PK), bank, bankFee
invoiceDetails - incDetails (PK), Section, Description, invcID (FK with type number)

以下是我用于将数据插入两个表的查询。

INSERT INTO invoice([bank], [bankFee]) VALUES (@bank,@bankFee)
OleDbCommand command = new OleDbCommand(queryString, conection);
command.Parameters.Add("@bank",txtBank.Text);
command.Parameters.Add("@bankFee",txtBankFee.Text);
int invoiceID = (int)command.ExecuteNonQuery();

INSERT INTO invoiceDetails ([section], [description],[invcID]) VALUES (@section,@description,@invcID)
OleDbCommand command = new OleDbCommand(queryString, conection);
command.Parameters.Add("@section",txtSection.Text);
command.Parameters.Add("@description",txtDescription.Text);
command.Parameters.Add("@invcID",invoiceID);
command.ExecuteNonQuery()

第一个查询运行正常,但第二个查询引发类型不匹配的异常。我尝试使用DMax(),但我仍面临例外Data type mismatch in criteria expression

更新  以下是表结构

table - invoiceID
invcID - Primary Key - data type auto number
bank - data type text
bankFee - data type text

table - invoiceDetails incDetails - Primary Key - data type auto
number Section - data type text Description - data type text InvcID -
foreign key - data type number

我可以获取最新添加发票的发票ID。但是我仍然遇到数据类型不匹配错误。

 double invoiceID = (double)command.ExecuteNonQuery(); 
 long invoiceID = (long)command.ExecuteNonQuery();

任何帮助?

0 个答案:

没有答案