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
Ajit N
NA
352
71.5k
How To Delete Multiple Selected Rows of Datagridview ?
Jan 7 2017 5:46 AM
Hi, I want to delete selected rows of datagridview and from database also.
So, I tried following code, but only one row are deleted at one time in datagridview and also selected row are not delete from database.
so, plz help me..
This is my code..
SqlCommand delcmd =
new
SqlCommand();
if
(dataGridView1.Rows.Count > 1 && dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count - 1)
{
delcmd.CommandText =
"DELETE FROM StudentRegistration WHERE Rollno="
+ dataGridView1.SelectedRows[0].Cells[0].Value.ToString() +
""
;
//con.Open();
delcmd.Connection = con;
delcmd.ExecuteNonQuery();
//con.Close();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
MessageBox.Show(
"Row has been Deleted"
);
}
Reply
Answers (
3
)
How To send a notification message to users of application
Move controls automatically when Dragover on table layout p