【发布时间】:2016-03-23 19:56:35
【问题描述】:
我有 PHP 背景,在尝试 ASP.NET webAPI 时遇到了问题。
我有一个 MySQL 数据库和一个包含一些文件信息的表。 现在我想做一个“SELECT * FROM Files”并在 XML 中查看结果。
如何呈现返回的查询结果?
这是我目前的代码,
模特:
namespace ProductsApp.Models
{
public class File
{
public int Id {get; set;}
public string Text {get; set;}
}
}
控制者:
public IEnumerable<File> Get()
{
try
{
command = conn.CreateCommand();
command.CommandText = "SELECT * FROM Files";
conn.Open();
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//How to output the rows ????
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return null; // return the list
}
【问题讨论】:
-
代码是文本。发布文字图片基本上是无用的。
-
对不起!现在感谢 Jason Watkins!
-
有人可以帮忙吗? :(
标签: c# mysql asp.net-web-api asp.net-web-api2