CRUD Operations using DataGridView, DataTable and DataAdapter - Cannot add new row to DataGridView

后端 未结 2 1277
一向
一向 2020-11-27 23:37

I\'m trying to insert new records into the source table from the C# interface grid view.... But when I retrieve the records with the buttonclick code shown below... Im getti

2条回答
  •  抹茶落季
    2020-11-28 00:24

    Code is using ExecuteNonQuery, it returns no of rows affected not the results your query returns.

    Use ExecuteReader instead.

    var reader = cmd1.ExecuteReader();
    DataTable dt = new DataTable();
    dtLoad(reader);
    

    Is there any option or property for enabling the insertion option in the gridview

    dataGridView1.ReadOnly = false;
    dataGridView1.EditMode = DataGridViewEditMode.EditOnF2; //if you want to edit on F2.
    

提交回复
热议问题