namespace Web7.Models
{
public class C_F_BuyCert
{
public string C_Id
{ get; set; }
public string Buy_Id
{ get; set; }
public string Spy_Id
{ get; set; }
}
}
namespace Web7.Controllers
{
public class C_F_BuyCertController : Controller
{
public DataTable Index()
{
string ConnectString = "data source=172.16.60.144/orcl;User Id=yzd4hub;Password=yzd4hub;";
OracleConnection conn = new OracleConnection(ConnectString);
try
{
conn.Open();
string sql = "select * from c_f_buycert";
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataAdapter oda = new OracleDataAdapter(cmd);
DataTable ds = new DataTable();
oda.Fill(ds);
conn.Close();
cmd.Dispose();
return ds;
}
finally
{
conn.Close();
}
}
}
}
@model IEnumerable
@{
ViewBag.Title = "Index";
}
return ds;
不能這麼寫
你應該
List<頁面綁定的Model> model = new List<頁面綁定的Model>();
foreach (var row in ds.Tables[0].Rows)
{
model.Add(new 頁面綁定的Model() { C_id = row["C_id字段名"], Buy_Id = row["字段名"], ... });
}
return View(model);