First of all, I looked up this related question in here but the solution dataGridView1.Rows.Add() doesn\'t work in my case.
In my Datagridview, I have
When I write this line in Form_Load
DGVData.DataSource = DataSQLite.GetData("SELECT * from tableName");
And trying to add a new row this error appeared to me
Instead of using DataSource try this code
private void Form_Load(object sender, EventArgs e) {
DataSQLite.OpenDB(); // this line to open connection to Database and DataSQLite class i created it
DataTable tbl = DataSQLite.GetData("SELECT * from tableName");
for (int i = 0; i < tbl.Rows.Count; i++) {
DGVData.Rows.Add(); // this line will create new blank row
for (int j = 0; j < Numberofcolumns; j++) {
DGVData.Rows[i].Cells[j].Value = tbl.Rows[i][j].ToString();
}
}
}
After this code you can easily add rows