我想根据 SQLDataReader 读取的输出输出一个字符串(或者可能是其他变量类型,如果字符串不理想)。我一直在玩“while”循环, while (reader.Read())
我需要得到一些可以用 json.net 序列化的东西。
这是我当前的代码 - 它输出到调试日志只是为了确保我成功地从数据库读取。
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "Data Source =.\\SQLEXPRESS; Initial Catalog = TeamProject; Integrated Security = True; MultipleActiveResultSets = True";
string querystring = "RosterMake";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(querystring, connection);
command.CommandType = CommandType.StoredProcedure;
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
System.Diagnostics.Debug.WriteLine("\t{0}\t{1}\t{2}",
reader[0], reader[1], reader[2]);
// What do I put here to make the results something …Run Code Online (Sandbox Code Playgroud)