我正在尝试建立一个预订系统,其中所有客户名称都可以显示与特定预订相关联,一旦输入预订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();