What's wrong with these parameters?

只愿长相守 提交于 2019-11-26 23:19:05
devio

Simply ask google, I guess more than 10000 hits is quite impressive. Your argument "I don't think that..." is not valid until you proved it.

This is what MSDN says:

The OLE DB.NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:

SELECT * FROM Customers WHERE
CustomerID = ?

Therefore, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

The problem is because the parameters are not in the same order when you are adding them.

For example, in your commented line (//adapter.InsertQuery...), you have DocID and then RecievedDay...yet when you are adding them, you first add DocID and then add SourceID.

Make sure that they are in the same order...and this applies to both sql statements or stored procedures.

This is because ADO.NET does not support named parameters when using an OLEDB provider, and since you are connecting to an Access DB, you are infact using an OLEDB provider...so the order of the parameters does matter.


If they are in order, and it's still not working, then I think that it might be an issue with the DateTimes;
Try converting it to string before adding it as a parameter :

cmd.Parameters.AddWithValue("@ReceivedDay", ReceivedDay.ToShortDateString());
cmd.Parameters.AddWithValue("@DueDay", DueDay.ToShortDateString());

And also make sure that the format of the date is in U.S. format (m/d/yyyy) or ISO Format (yyyy-mm-dd)

OleDb does not support named parameters, so the answer of Dreas is correct.

When you use OleDb, then you have to add the parameters in the same order as they appear in the query, since the names that you give them, are not used.

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