-7

可能重复:
存储过程返回到 C# .Net 中的 DataSet

如何使用 C# 从我的项目中调用存储过程?我需要将该存储过程的输出放入数据表中,但出现错误。

代码:

private string connectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=blablalbla;";
    private DataTable dtProductPrijsActueel = new DataTable();
    public DataTable productPrijsActueel()
    {
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();
        SqlCommand comm = conn.CreateCommand();
        comm.CommandType = CommandType.StoredProcedure;
        comm.CommandText = "procSelectPrijsActueel";

        dtProductPrijsActueel.Load(comm.ExecuteReader());
        conn.Close();
        conn.Dispose();

        return dtProductPrijsActueel;
    }

错误:

ERROR : KEYWORD NOT SUPPORTED : 'PROVIDER'
4

1 回答 1

1

确实是应该刚刚被谷歌搜索的东西,但是您正在寻找的一般代码看起来像这样:

  string connect = System.Configuration.ConfigurationManager.AppSettings["conn"];
  SqlConnection connection = new SqlConnection(connect);
  string spName = "TheSpName";

  SqlCommand spCmd = new SqlCommand(spName, connection);
  spCmd.CommandType = CommandType.StoredProcedure;

  spCmd.Parameters.Add("@SomeParam", SqlDbType.String).Value = "Some Parameter";

  connection.Open();

  var dataTableReader = spCmd.ExecuteReader();
于 2012-11-28T21:01:10.077 回答