【问题标题】:How to use an MS Access parameterized stored procedure in ADO.NET?如何在 ADO.NET 中使用 MS Access 参数化存储过程?
【发布时间】:2009-09-14 14:19:27
【问题描述】:

在 MS Access 中,我有一个带有两个参数的查询,我想在带有 TableAdapter 的 ADO.NET 数据集中获取此查询的结果。

在 Visual Studio Express 2008 中,我无法在助手中选择查询。事实上,我似乎无法选择任何带有参数的查询。有没有办法在 ADO.NET 中使用 am Access 参数化查询?

【问题讨论】:

    标签: sql ms-access ado.net tableadapter


    【解决方案1】:

    查询1

    SELECT * FROM EMP where eno=meno and ename=mename
    

    Popuplate DataTable 实例

    OleDbConnection cn = new OleDbConnection(@"connect_string");
    OleDbCommand cmd = new OleDbCommand("query1", cn);
    cmd.CommandType = CommandType.StoredProcedure;
    
    cmd.Parameters.Add("meno", OleDbType.Integer, 4, "eno");
    cmd.Parameters.Add("mename", OleDbType.VarChar, 40, "ename");
    cmd.Parameters[0].Value = 44;
    cmd.Parameters[1].Value = "ddd";
    
    OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
    DataTable dt = new DataTable();
    adp.Fill(dt);
    

    【讨论】:

    • 您好,感谢您的回答。我没有使用您的代码,但我在 DataSet 编辑器中完成了您的所有代码,并且它有效。
    猜你喜欢
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 2021-05-03
    • 1970-01-01
    • 2021-12-29
    • 2013-09-18
    相关资源
    最近更新 更多