Populating DataGrid in Visual Studio from Access D

2019-09-08 03:52发布

问题:

I have a datagrid in my form. What I did was I made an OleDb connection to my database in access, then I made a dataset in my project and put my Food table in that. Then on the page that contains the form, I added a dataset (dataset11) from the Data Toolbox that links to dataset1.xsd in my project. I then put the data source on my datagrid to dataset11.Food (Food being the table I want to display). This adds the two fields in that table to the datagrid (id and size) but none of the data I put in in access shows up! There are 15 entries in this table but they don't show up on my datagrid even when I run the program. What am I doing wrong???!?!!?!?!?

Here is a picture: http://i39.tinypic.com/2rr43yf.png

Edit added code from external link

Me.DataGrid1.DataBindings.Add(New System.Windows.Forms.Binding("Tag", Me.Dataset11, "Food.Size"))
Me.DataGrid1.DataBindings.Add(New System.Windows.Forms.Binding("DataSource", Me.Dataset11, "Profile.ProfileName"))
Me.DataGrid1.DataBindings.Add(New System.Windows.Forms.Binding("DataMember", Me.Dataset11, "Profile.ProfileName"))
Me.DataGrid1.DataBindings.Add(New System.Windows.Forms.Binding("Visible", Me.Dataset11, "Profile.ProfileName"))
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.Dataset11.Profile
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(296, 8)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(384, 256)
Me.DataGrid1.TabIndex = 12