insert updated datagrid rows into database
Hi Friends!
How can I insert updated datagrid rows into database.
what about this code? it has no error but there's no update into database
public void updateGridServico(DataGridView dtg, string idAluno)
{
int i = 0;
List<int> ChkedRow = new List<int>();
for (i = 0; i <= dtg.RowCount - 1; i++)
{
if (Convert.ToBoolean(dtg.Rows[i].Cells["checkMe"].Value) == true)
{
ChkedRow.Add(i);
}
}
if (ChkedRow.Count == 0)
{
MessageBox.Show("Selecione pelo menos um Servico!");
vazio = true;
return;
}
else
{
vazio = false;
foreach (int j in ChkedRow)
{
string str;
str = @"update tbAlunoServico set Servico = '" + dtg.Rows[j].Cells["descr"].Value + "', percentagem = '" + dtg.Rows[j].Cells["perc"].Value + "' where idAlunoServc= '" + idAluno + "'";
try
{
using (SqlConnection myconn = new SqlConnection(con.stringConexaoRH()))
{
using (SqlCommand comand = new SqlCommand(str, myconn))
{
myconn.Open();
comand.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//MessageBox.Show("Dados inseridos com sucesso!");
}
}