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
Mohamed Shakir
NA
7
5k
to delete checked rows in grid view
Jul 31 2014 5:21 AM
private void button3_Click(object sender, EventArgs e)
{
// string query = "DELETE FROM [payments] WHERE date = " + dateToDelete;
int i = 0;
List<int> ChkedRow = new List<int>();
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
if (Convert.ToBoolean(dataGridView1.Rows[i].Cells["Column1"].Value) == true)
{
ChkedRow.Add(i);
}
}
if (ChkedRow.Count == 0)
{
MessageBox.Show("Select one checkbox");
return;
}
foreach (int j in ChkedRow)
{
// cnnStr = @"DELETE from (date,custname,description,chqno,duedate,accname,amount)
// where ('" + dataGridView1.Rows[j].Cells["dateDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["custnameDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["descriptionDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["chqnoDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["duedateDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["accnameDataGridViewTextBoxColumn"].Value + "','" + dataGridView1.Rows[j].Cells["amountDataGridViewTextBoxColumn"].Value + "');";
cnnStr = "DELETE FROM [payments] WHERE ('" + dataGridView1.Rows[j].Cells["payidDataGridViewTextBoxColumn"].Value + "');";
try
{
using (SqlConnection cs = new SqlConnection(ConnectionString))
{
using (cmd = new SqlCommand(cnnStr, cs))
{
cs.Open();
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
MessageBox.Show("Records deleted Succesfully");
}
Reply
Answers (
1
)
equivalent of push from javascript to c#
Flag quiz