0

I have a DataGridView that I'm trying to pull data to from an SQLite database.

The structure of the DataGridView is:

  • TaskName : String
  • TaskDueDate : String
  • Status : ComboBox

Code:

String SelectQuery = "Select TaskName,TaskDue,Status from TASKS Order BY Status";
SQLiteConnection slite = new SQLiteConnection("data source = Dash.sqlite");
slite.Open();

SQLiteDataAdapter data = new SQLiteDataAdapter(SelectQuery, slite);
SQLiteCommandBuilder Command = new SQLiteCommandBuilder(data);

DataTable table = new DataTable();

data.Fill(table);
MyTasksGrid.AutoGenerateColumns = false;
MyTasksGrid.DataSource = table;

I've spent the past few hours on here looking at several question including this one, however it was producing the exact same results for me as the code above.

This question also suggests my code is correct from the accepted answer?

I get the correct amount of rows showing up in the grid, but all the cells are blank. If I remove the AutoGeneratColumns line it adds the data but in new columns, which I don't want. (I want it to be added in the already defined columns.) Could anyone give me a hand to see where I am going wrong?

2
  • You need to add a binding which maps the column in the data grid to the corresponding column in the data table. Commented Jul 20, 2014 at 21:17
  • Thank You, that worked perfectly. Needed to set the DataPropertyName too. Commented Jul 20, 2014 at 21:38

1 Answer 1

1
String SelectQuery = "Select ID,TaskName,TaskDue,Status from TASKS Order BY Status";
   SQLiteConnection slite = new SQLiteConnection("data source = SupportDash.sqlite");
   slite.Open();

   SQLiteDataAdapter data = new SQLiteDataAdapter(SelectQuery, slite);
   SQLiteCommandBuilder Command = new SQLiteCommandBuilder(data);
   var Bind = new BindingSource();
   DataTable table = new DataTable();

   Bind.DataSource = table;

   MyTasksGrid.AutoGenerateColumns = false;
   MyTasksGrid.DataSource = table;

   MyTasksGrid.DataSource = Bind;
   MyTasksGrid.Refresh();

   data.Fill(table);

I also needed to add the 'DataPropertyName' in the control properties.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.