方法写好了,怎样在.aspx.cs里调用?将编辑的内容显示到文本框里。 public class BookService
{
public List<book> getAllbooks()
{
int CategoryId = 0;
int PublisherId=0;
List<book> li = new List<book>();
string sql = "select * from books";
SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
sda.Fill(ds);
if(ds.Tables.Count>0)
{
DataTable dt = ds.Tables[0];
foreach(DataRow dr in dt.Rows)
{
book book = new book(); book.Id = (int)dr["Id"];
book.Author = dr["Author"].ToString();
book.ISBN = (string)dr["ISBN"];
book.UnitPrice = (Decimal)dr["UnitPrice"]; book.PublishDate =(DateTime)dr["PublishDate"];
book.Title = (string)dr["Title"];
CategoryId = (int)dr["CategoryId"];
PublisherId = (int)dr["PublisherId"]; book.Publish = new PublishService().getPbyId(PublisherId);
book.Category = new CategroyService().GetCbyId(CategoryId);
li.Add(book);
}
}
return li;
}
}
}
{
public List<book> getAllbooks()
{
int CategoryId = 0;
int PublisherId=0;
List<book> li = new List<book>();
string sql = "select * from books";
SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
sda.Fill(ds);
if(ds.Tables.Count>0)
{
DataTable dt = ds.Tables[0];
foreach(DataRow dr in dt.Rows)
{
book book = new book(); book.Id = (int)dr["Id"];
book.Author = dr["Author"].ToString();
book.ISBN = (string)dr["ISBN"];
book.UnitPrice = (Decimal)dr["UnitPrice"]; book.PublishDate =(DateTime)dr["PublishDate"];
book.Title = (string)dr["Title"];
CategoryId = (int)dr["CategoryId"];
PublisherId = (int)dr["PublisherId"]; book.Publish = new PublishService().getPbyId(PublisherId);
book.Category = new CategroyService().GetCbyId(CategoryId);
li.Add(book);
}
}
return li;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货