将表的数据加载到运行时创建的 DataGridView 中
每当我按下按钮时,我都会尝试在运行时创建一个 DataGridView。
我还想显示数据库中表中的数据。
当我按下按钮时,应该创建一个 DataGridView 并显示数据,但它什么也没做。它不会创建 DataGridView。
这是我的代码(该表称为“供应”):
public partial class managerpage : Form
{
int idWorkersDB = 0;
int idAccountsDB = 1;
int idSuppliersDB = 2;
int idOtherDB = 3;
public static DataGridView workersView = new DataGridView();
public static DataGridView suppliesView = new DataGridView();
public static DataGridView accountsView = new DataGridView();
int clickedID;
private void picBoxSuppliers_MouseUp(object sender, MouseEventArgs e)
{
suppliesView.Location = new Point(59, 51);
suppliesView.Size = new Size(749, 399);
clickedID = idSuppliersDB;
dataDBPanel.Visible = true;
dataDBPanel.Dock = DockStyle.Fill;
titleDataLbl.Text = "Suppliers Data";
titleDataLbl.Left = (this.Width - titleDataLbl.Width) / 2;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\project\FUCKINGVISUALSTUDIOISSOSHIT\loginData.mdb");
OleDbDataAdapter cmd = new OleDbDataAdapter("SELECT * FROM supplies", con);
con.Open();
DataTable tbl = new DataTable();
cmd.Fill(tbl);
con.Close();
suppliesView.DataSource = tbl;
suppliesView.Show();
}
}
I'm trying to create a DataGridView at runtime whenever I press a button.
I also want to present the data from a table in my database.
When I press the Button that should create a DataGridView and show the data, but it just does nothing. It doesn't create the DataGridView.
Here is my code (the table is called "supplies"):
public partial class managerpage : Form
{
int idWorkersDB = 0;
int idAccountsDB = 1;
int idSuppliersDB = 2;
int idOtherDB = 3;
public static DataGridView workersView = new DataGridView();
public static DataGridView suppliesView = new DataGridView();
public static DataGridView accountsView = new DataGridView();
int clickedID;
private void picBoxSuppliers_MouseUp(object sender, MouseEventArgs e)
{
suppliesView.Location = new Point(59, 51);
suppliesView.Size = new Size(749, 399);
clickedID = idSuppliersDB;
dataDBPanel.Visible = true;
dataDBPanel.Dock = DockStyle.Fill;
titleDataLbl.Text = "Suppliers Data";
titleDataLbl.Left = (this.Width - titleDataLbl.Width) / 2;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\project\FUCKINGVISUALSTUDIOISSOSHIT\loginData.mdb");
OleDbDataAdapter cmd = new OleDbDataAdapter("SELECT * FROM supplies", con);
con.Open();
DataTable tbl = new DataTable();
cmd.Fill(tbl);
con.Close();
suppliesView.DataSource = tbl;
suppliesView.Show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您隐藏了大部分代码,但我怀疑您从未将 SupplyView (数据网格视图?)添加到表单中。下面是一个运行良好的示例代码:
You are hiding most of the code, but I suspect you never add that suppliesView (a datagridview?) to the form. Here is a sample code that works wonderfully well: