>how to populate dataGridView Columns with data coming from database when Columns already exist in c#
You can use list or datatable object.
i want to populate the column on the gridview which i have added manually on the gridview,i want data to get displayed on that column.I have tried it but this code displays data on the other column which is created automatically not on the column which i have added.
Well, lets say the column index is 0, a.k.a the first column. What you could do is fine the number of rows retrieved, I am sure there is an MySQL command to find # of rows, and iterate in a FOR loop, were you can create an array with the same # of elemnts as columns. Populate the appropriate index of the array with the index you want to display that information in the DataGridView. Then use the DataGridiew.add or addRow function (I forget which one) and pass the array as a parameter. The (for) loop will do this for each and every row in the database:
here is an example:
numRows = 5 // # of rows in the database
numCols = 4 // # of columns in the DataGridViw
String row = new String[numCols];
for(int i = 0; i < numRows; i++)
for(int j = 0; j < numCols; j++)
row[j] = DataFOrColumnJ here;
Of course that needs a LOT of tweaking, but I made it in like 1 minute. I hope this helps you!