gpt4 book ai didi

c# - DataGridView 不显示我的列

转载 作者:行者123 更新时间:2023-11-30 22:10:23 31 4
gpt4 key购买 nike

我在 C# 中有一个 MySQL 连接,据说可以将表数据放入 DataGridView,但它有一个问题,它会在我的数据库中为我的用户表中的每个帐户生成行,但它不显示实际数据。谁能帮忙?

我的代码:

public Form1()
{
InitializeComponent();

string connectionString = "Server=mysql.dunkycart.com; Database=dunkycart; Uid=dunkycart; Pwd=rooB-dnK-sqL;"; //Set your MySQL connection string here.
string query = "SELECT name, username, email FROM users"; // set query to fetch data "Select * from tabelname";
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
{
DataSet ds = new DataSet();
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}

问题: This is the output of the form. I entered the column names manually, btw, so it's not doing that either.

最佳答案

没关系,我刚找到一个修复程序。我必须做的是将 DataGridView 中每一列的 DataPropertyName 设置为数据库表中的相应列。

关于c# - DataGridView 不显示我的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40265702/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com