SQL过程
CREATE PROCEDURE xxx.test
@p1 int
AS
BEGIN
SET NOCOUNT ON;
SELECT @p1
END
C#source
using(OdbcConnection Connection=new OdbcConnection("Driver={SQL Native client};SERVER=###;DATABASE=###;Trusted_Connection=yes;"))
{
Connection.Open();
using(OdbcTransaction Trans=Connection.BeginTransaction())
{
using(OdbcCommand Command=Connection.CreateCommand())
{
try
{
Command.CommandType = System.Data.CommandType.StoredProcedure;
Command.CommandText = "xxx.test";
Command.Transaction = Trans;
OdbcParameter param=new OdbcParameter("@p1",OdbcType.Int);
param.Value = 1;
Command.Parameters.Add(param);
Command.ExecuteNonQuery();
}
catch (OdbcException OdbcException)
{
Console.Write(OdbcException.Message);
}
}
Trans.Rollback();
}
Connection.Close();
}
我总是异常说ERROR [42000] [Microsoft] [SQL Native Client] [SQL Server]程序或功能' test'期望参数' @ p1',这是未提供的。"
然而,当我调试时,将断点放在行ExecuteNonQuery上并单击Command.Parameters直到我看到项目我可以看到此参数肯定存在并且其值已设置,类型是正确的 - 请参阅http://s29.postimg.org/5cqvo7iqv/Visicom_Windows.png(i还没有足够的声誉)
我做错了什么?