TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sousa Pambo
NA
92
24.2k
insert updated datagrid rows into database
Mar 5 2015 8:38 PM
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!");
}
}
Reply
Answers (
0
)
diff b/e Convert.ToInt32 and (int)
how to use string builder