//cria conexao com o DB
OleDbConnection aConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Casa\Desktop\Inventario.mdb");
//comando SQL
OleDbCommand aCommand = new OleDbCommand("INSERT INTO Inventario (CodProd, Qtd, ValorUnit, ValorMerc)" + "Values (@CodProd,Qtd, @ValorUnit, @ValorMerc)", aConnection);
aConnection.Open();
try
{
//percorro o DataGridView
for (int i = 0; i < vGrade.Rows.Count - 1; i++)
{
//limpo os parâmetros
aCommand.Parameters.Clear();
//crio os parâmetro do comando
//e passo as linhas do dgvClientes para eles
//onde a célula indica a coluna do dgv
aCommand.Parameters.AddWithValue("@CodProd",
vGrade.Rows[i].Cells[0].Value);
aCommand.Parameters.AddWithValue("@Qtd",
vGrade.Rows[i].Cells[1].Value);
aCommand.Parameters.AddWithValue("@ValorUnit",
vGrade.Rows[i].Cells[2].Value);
aCommand.Parameters.AddWithValue("@ValorMerc",
vGrade.Rows[i].Cells[3].Value);
//executo o comando
aCommand.ExecuteNonQuery();
}
MessageBox.Show("Concluído");
//fecha a conexao
aConnection.Close();
}
catch (FormatException)
{
MessageBox.Show("Houve um erro");
}
}
How can I implement progressbar in the above code?
I was using the code below to perform a similar task (display the progress of the action), but I do not know how to implement it in the code above, what should I do?
try
{
aConnection.Open();
//cria objeto datareader para conexao com a tabela
OleDbDataReader aReader = aCommand.ExecuteReader();
while (aReader.Read())
{
progressBar1.Increment(1);
label1.Text = progressBar1.Value.ToString() + "%";
}
//fecha o reader
aReader.Close();
//fecha a conexao
aConnection.Close();
}
finally { }
}*/