0
我有以下方法運行大約20個SQL查詢。將結果返回給客戶端的最佳方式是什麼?返回多個sql查詢結果 - C#
public int Results()
{
using (var conn = GetConnection())
using (var cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"SELECT TOP 1 stdent_number from Students";
conn.Open();
var result = (int)cmd.ExecuteScalar();
cmd.CommandText = @"SELECT TOP 1 class_number from Classes";
var number = (int)cmd.ExecuteScalar();
cmd.CommandText = @"SELECT TOP 1 table from Tables";
var table = (int)cmd.ExecuteScalar();
cmd.CommandText = @"SELECT TOP 1 suite from Suites";
var suite = (int)cmd.ExecuteScalar();
.....
//I want to return result, number, table and suite so they can be populated on client
//What is the best way to return? Should I create IEnumerable and add values to it and return
//as IEnumerable or should these be returned all separately or as a dictionary?
//Also this is just an example in real time I have at least 15 values from sql queries that I //want to return
}
}
Pandian - 其實我們不是找誰g創建一個存儲過程。有沒有其他更好的方法來做到這一點? – NoviceMe
@NoviceMe: - 我已經更新了我的代碼與出proc ...試試這.. – Pandian