0

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?

enter image description here

NoName
  • 7,940
  • 13
  • 56
  • 108

2 Answers2

0

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

Community
  • 1
  • 1
Stuart
  • 143
  • 1
  • 3
  • 18
0

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.

Community
  • 1
  • 1
Suvro
  • 352
  • 2
  • 13