我正在尝试制作一个预订系统,其中所有客户姓名都可以显示与特定预订相关联,一旦输入预订 ID,我就有一个 linq 表,我不知道如何连接 SQL 数据库并显示在一个gridview,这是我下面的代码
public partial class BookingGuests : System.Web.UI.Page
{
private HotelConferenceEntities datacontext = new HotelConferenceEntities();
private void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
int id = int.Parse(BookID.Text.ToString());
tblBooking booking = datacontext.tblBookings.SingleOrDefault(x => x.BookingID == id);
tblVenue venue = datacontext.tblVenues.SingleOrDefault(x => x.VenueID == booking.Venue);
List<tblCustomer> customers = new List<tblCustomer>();
List<tblBookingGuest> guests = booking.tblBookingGuests.ToList();
foreach (tblBookingGuest guest in guests)
{
tblCustomer newcust = datacontext.tblCustomers.SingleOrDefault(x=>x.CustomerID == guest.CustomerID);
customers.Add( newcust);
}
int count = customers.Count;
GridView1.DataSource = customers;
GridView1.DataBind();