Wiooo Wiooo - 7 months ago 53
C# Question

DataGridView not showing my columns

I have a MySQL connection in C# that supposedly puts the table data into a

, but it has a problem and it makes the rows for every account in my users table in my db, but it doesn't show the actual data. Can anyone help?

My code:

public Form1()

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();
dataGridView1.DataSource = ds.Tables[0];

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


Because you are using DataSet instead of DataTable so you need to change this:


To this:


Or you can use a DataTable instead of DataSet:

DataTable dt = new DataTable();