Hi,
In a more general way if you are looking for inserting a record into a SQL database you can find a nice and very well explain article in the below links:
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[
^]
Inserting values into a SQL Server database using ado.net via C# - Stack Overflow[
^]
After making sure that you know how to do CRUD on a db via ADO.Net then we can continue with the following steps:
You stored the result of query in a sqlDataReader now you need to create a custom
DataTable
that contains the same columns (
DataColumns
) that your sqlDataReader contains and then use
Rows
property of
DataTable
to add records one-by-one and at the end bind your
DataTable
to your DataGridView.
var dataTable = new DataTable();
dataTable.Columns.Add("Col1");
dataTable.Columns.Add("Col2");
dataTable.Rows.Add(new object[]{"Rod", "Stephens"});
var bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
DataGridView1.DataSource = bindingSource;
A more complete example can be found at the following link:
Build a DataTable and bind it to a DataGridView in C#C# Helper[
^]
If this did not solve your problem then please leave a comment and I will assist you by improving my solution until your problem gets solved.
Cheers,
AH