c# - How to display my database created with EF Code First in DataGridView? -


I am trying to display my DB table in a DataGridView. I have created a database using EF code first approach here. Here are my DB classes:

  Public class blood donation {public int blood donation id {receipt; Set; } Public string firstname {get; Set; } Public String LastName {get; Set; } Date of birth date of public date received; Set; } Public DateTimeDelection {Receive; Set; } Public Bloodprit Bloodtip {get; Set; } Public Virtual List & lt; Blood donation & gt; Donation [receive; Set; }} Public class blood donation {public at blood donation} {received; Set; } Public Date Time Date {Receive; Set; } Public Virtual Blood Donor Blood Donor {Received; Set; }} Public Square BloodBankContext: DbContext {Public BloodBankContext (): Support ("BloodBankDatabase1") {Database.SetInitializer & LT; BloodBankContext & gt; (New DropCreateDatabaseAlways & lt; BloodBankContext & gt; ()); } Public DbSet & lt; BloodDonor & gt; Blood donor {receive; Set; } Public DbSet & lt; Blood donation & gt; Donation [receive; Set; }}  

Here is your main form:

  Public Partial Class BloodBankManager: Form {public static BloodBankContext Reference; Public Bloodbank Manager () {Initial Group (); Context = new blood bank consort (); Example Data Filler Example Data Filler = New Example Data Filler (reference); Var query = B in the context Select bludoners; Foreach (query in top renderer) {MessageBox.Show (donor.BloodDonorId + "" + donor.FirstName + "" + donor.LastName + "" + donor.DateofBirth.ToShortDateString () + "" + donor.BloodType); }} Private Zero Form1_Load (Object Sender, EventArgs e) {} Private Zero newBloodDonorButton_Click (Object Sender, EventArgs e) {NewBloodDonorForm newBloodDonorForm = NewBloodDonorForm (new); NewBloodDonorForm.bloodBankManager = This; NewBloodDonorForm.Show (); }}  

My DB seems to work properly, but I have no idea how to display

  context.BloodDonors  < DataGridView in / pre> 

I tried to use the DataSource Wizard in DataGridViewProperty, but when I run DataGridView for the first time the BloodDonors table will not update after the application runs. Any ideas on the easiest possible way to enclose the table to DataGridView?

itemprop = "text">

You need to force DataGridView.DataSource property < / P>

Read more here

Here is a code example

  using the system; Using System.Data; Using System.Windows.Forms; Using System.Data.SqlClient; Name Location WindowsApplication1 {Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); } Private Zero Button 1_Click (Object Sender, EventArgs E) {String Connection String = "Data Source = Initial Catalog = Pub; Integrated Security = True"; String SQL = "Select * From Author"; SqlConnection connection = new SqlConnection (connectionString); SqlDataAdapter Data Adapter = New SqlDataAdapter (SQL, Connection); Dataset ds = new dataset (); Connection.Open (); DataAdapter.phill (DS, "Authors_table"); Connection.Close (); DataGridView1.DataSource = DS; DataGridView1.DataMember = "Author-Eligible"; }}}  

here

is another link with more information

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -