I'm here to ask you one thing.
Can I add this data from datagridview to database with consumidor final
id, clicking at Confirmar
button?
I'm here to ask you one thing.
Can I add this data from datagridview to database with consumidor final
id, clicking at Confirmar
button?
Provided that the schema of the DataTable is the same as the schema of the database table you can just use a DataAdapter to insert the data. Have a look here: How can I add data from DataTable to database table directly? Stuart
As you can try this:
SqlConnection sqlConnection = new SqlConnection(ConnString))
SqlCommand sqlCommand = new SqlCommand()
sqlCommand.Connection = sqlConnection;
sqlConnection.Open();
for(int i=0; i< myDataGridView.Rows.Count;i++)
{
query= @"INSERT INTO tableName VALUES ("
+ ddlConsumidorFinalId.SelectedValue + ", "
+ myDataGridView.Rows[i].Cells["ColumnName"].Value +", "
+ myDataGridView.Rows[i].Cells["ColumnName"].Value +");";
//Add as pre table fields
sqlCommand.CommandText = query;
sqlCommand.ExecuteNonQuery();
}
For more, See this.