加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 通过ODBC执行参数化SQL StoredProcedure

发布时间:2020-12-15 17:40:50 所属栏目:百科 来源:网络整理
导读:在C#WinForms应用程序中,我必须在MS SQL Express服务器上执行参数化存储过程.数据库连接工作,过程工作,但我收到一条错误消息: 42000: Missing Parameter ‘@KundenEmail’ 虽然我确定我正确添加了参数.也许你们中的一些人可以看看 – 我不知道该怎么搜索…
在C#WinForms应用程序中,我必须在MS SQL Express服务器上执行参数化存储过程.数据库连接工作,过程工作,但我收到一条错误消息:

42000: Missing Parameter ‘@KundenEmail’

虽然我确定我正确添加了参数.也许你们中的一些人可以看看 – 我不知道该怎么搜索……

OdbcConnection ODBCConnection = new OdbcConnection();

try
{
    ODBCConnection.ConnectionString = ODBCConnectionString;
    ODBCConnection.Open();
}
catch (Exception DatabaseConnectionEx)
{
    if (ODBCConnection != null)
        ODBCConnection.Dispose();

    // Error Message

    return null;
}

OdbcParameter ODBCParameter = new OdbcParameter("@KundenEmail",OdbcType.NChar,50);
ODBCParameter.Value = KundenEmail;

OdbcCommand ODBCCommand = new OdbcCommand("getDetailsFromEmail",ODBCConnection);
ODBCCommand.CommandType = CommandType.StoredProcedure;
ODBCCommand.Parameters.Add(ODBCParameter);

DataTable DataTable = new DataTable();

OdbcDataAdapter ODBCDatadapter = new OdbcDataAdapter(ODBCCommand);
ODBCDatadapter.Fill(DataTable);
ODBCDatadapter.Dispose();

ODBCConnection.Close();
ODBCConnection.Dispose();

这是我收到的错误消息:

ERROR [4200][Microsoft][ODBC SQL Server]The Procedure or method
‘getDetailsFromEmail’ expects the ‘@KundenEmail’-parameter,which
was not supplied.

啊,我错过了连接字符串

private static String ODBCConnectionString = "Driver={SQL Server};Server=TESTSRVSQLEXPRESS;Database=TestDatabase;";

有任何想法吗?提前致谢.

解决方法

好吧 – 我现在设法自己解决这个问题,在MSDN文档的帮助下.

通过ODBC执行存储过程的正确语句如下:

OdbcCommand ODBCCommand = new OdbcCommand("{call getDetailsFromEmail (?)}",ODBCConnection);
ODBCCommand.CommandType = CommandType.StoredProcedure;
ODBCCommand.Parameters.AddWithValue("@KundenEmail",KundenEmail);

不过 – 谢谢你的帮助Thorsten.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读