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