简体   繁体   English

一击从 sql server 获取所有组合值

[英]get all combo value from sql server in one hit

On my page i have multiple combos/dropdown in one screen and all the combos/dropdown are loading data from SQL.在我的页面上,我在一个屏幕中有多个组合/下拉列表,所有组合/下拉列表都从 SQL 加载数据。 for example if there is 20 combo then 20 time database would be called to fetch data in one request.例如,如果有 20 个组合,则将调用 20 个时间数据库以在一个请求中获取数据。 Is there any way to get all combos data in one SQL hit?有没有办法在一次 SQL 命中中获取所有组合数据?

Atually it is possible to return two (or more) datatables from stored procedure (I'm talking about MS SQL) Atually 可以从存储过程返回两个(或更多)数据表(我说的是 MS SQL)

Something like就像是

create procedure SampleDataSetResult
as
begin
 select * from table1
 select * from table2
end

Then this can be consumed like然后这可以像

var command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "SampleDataSetResult";
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
    DataSet dataset = new DataSet();
    da.Fill(dataset);

    // here you can use dataset tables
}

However this approach works with raw data from database.然而,这种方法适用于来自数据库的原始数据。 Also it contains datatables that do not have names to be analyzed.它还包含没有要分析的名称的数据表。 The only one is to synchronize datatable index between SP and source code and process this datatable data according to its index.唯一的就是同步SP和源代码之间的数据表索引,并根据它的索引处理这个数据表数据。 Like dataset.Tables[0] - is treated like combo data 1 etc. This can be tricky and all SP modifications have to be synchronized with source code.dataset.Tables[0] - 被视为组合数据 1 等。这可能很棘手,所有 SP 修改都必须与源代码同步。 Also having 20 combos on one page sounds a little bit strange.在一页上还有 20 个组合听起来有点奇怪。 I suppose that there will be combos data to be shown that depends from data selected in the previous combo.我想会显示组合数据,这些数据取决于在前一个组合中选择的数据。

I do not see any reason to save SQL queries count right now for you.我认为现在没有任何理由为您保存 SQL 查询计数。 If you have web page then you can try to use MVC approach and wrap database calls with view model method calls.如果您有网页,那么您可以尝试使用 MVC 方法并使用视图模型方法调用包装数据库调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM