无法在Winforms中显示记录到DataGridView
现在,我想在Winforms应用程序中显示它。我的应用程序包括看起来像这样的主页:
当我单击商店按钮时,我希望该程序将访问我创建的usercontrol1中的datagridview,并从我的创建并输入所有ID,名称和价格数据库中的数据库。 这就是我在主视图中将其制作的方式:
string connectionString = @"myconnectionString";
private void storeBtn_Click(object sender, EventArgs e)
{
userControl21.Hide();
userControl11.Show();
userControl11.BringToFront();
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
SqlDataAdapter sqlData = new SqlDataAdapter("SELECT * FROM \"Item\"", sqlCon);
DataTable mytable = new DataTable();
sqlData.Fill(mytable);
UserControl1 uctl1 = new UserControl1();
uctl1.storeGridView.AutoGenerateColumns = false;
uctl1.storeGridView.DataSource = mytable;
}
}
我也已经将datapropertyname放在我的usercontrol datagridview中,同一名称与我想要在数据库中获取记录的列。当我运行程序时,所有操作都会运行,没有发生错误,但是当我单击“存储”按钮时,什么都没有出现,没有显示记录。 我也尝试逐步调试,但仍然不知道为什么它没有收到任何记录。以这种速度,我真的很感谢任何帮助。
This is what my table "Item" look like in my database:
Now, I want to display it inside my winforms application. My application include the main page that look like this:
When I click the Store button, I expect the program will access the DataGridView inside UserControl1 that I have created and input all id, name and price from my database into it.
This is how I make it inside the main view page:
string connectionString = @"myconnectionString";
private void storeBtn_Click(object sender, EventArgs e)
{
userControl21.Hide();
userControl11.Show();
userControl11.BringToFront();
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
SqlDataAdapter sqlData = new SqlDataAdapter("SELECT * FROM \"Item\"", sqlCon);
DataTable mytable = new DataTable();
sqlData.Fill(mytable);
UserControl1 uctl1 = new UserControl1();
uctl1.storeGridView.AutoGenerateColumns = false;
uctl1.storeGridView.DataSource = mytable;
}
}
I already also putting DataPropertyName inside my UserControl DataGridView the same name with the column i want to get record in my database. And when I run program, everything run and there's no bug occured, but when I click the "Store" button, nothing come out, there's no record displayed.
I also try to debug step by step but still have no idea why it doesn't received any record. At this rate, I would really appreciate any help coming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论