如何使用c#从sql中检索多个数据表

问题描述 投票:0回答:0

我遇到一个问题。 我有一个通用函数,可以通过连接到我的 sql 数据库来执行存储过程。 在所有 SP 中,我只需要返回一个数据表。

   public DataTable ExecuteStoredProcedure(string SpName, bool byStoredProce, string[] Searchparam, DataTable dt)
        {

            oDataTable = null;
            oex = null;

            try
            {

                oDataTable = new DataTable(Convert.ToString(globalParm.cntDataTable));
                objCmd = new SqlCommand(SpName.ToString(), oConn);
                objCmd.CommandType = CommandType.StoredProcedure;
                if (!byStoredProce)
                {
                    objCmd.CommandType = CommandType.Text;
                }

                using (SqlCommand cmd = new SqlCommand(SpName.ToString(), oConn)) // 
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    fillData(SpName, ref Searchparam, cmd, dt);
                    da = new SqlDataAdapter(cmd);
                    da.Fill(oDataTable);
                }



            }
            catch (SqlException ex)
            {
                

            }
            return oDataTable;

        }

我添加了一个新的 sql SP,用于检索 2 个数据表。 为了获得任意数量的数据表,对上述函数的最佳修改是什么? 当我运行这个新的 SP 时,oDataTable 包含返回的数据表中的第一个(两个之间)。

c# sql stored-procedures datatable sqldataadapter
© www.soinside.com 2019 - 2024. All rights reserved.