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
junaid khurshid
NA
52
7k
datagrid in Wpf
Jun 29 2014 1:06 AM
I am using datagrid in my usercontrol in wpf
I am doing edit delete using selection change event . I edit or delete data from datagrid when i call datagrid load function it gives me exception "index out of range must be non negative......" my grid load function is this
private void grid_load()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select commanNameId, commanName As CommanName ,date As Date from commanNametbl where catageoryId='" + idlbl.Text + "' Order By commanName ASC", con);
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter dap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
dap.Fill(dt);
dataGrid1.ItemsSource = dt.DefaultView;
dataGrid1.UpdateLayout();
dataGrid1.Columns[0].Visibility = Visibility.Hidden;
}
and my delete button code is this
private void delbtn_Click(object sender, RoutedEventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Delete from commanNametbl where commanNameId='" + comBlock.Text + "'", con);
int ii = cmd.ExecuteNonQuery();
con.Close();
comanNametextBox.Text = "";
comNametextBlock.Text = "";
MessageBox.Show("Record Deleted Sucessfully!");
grid_load();
}
Thanks in Advance
Reply
Answers (
3
)
Display the clicked date from the calender tool in a label
How to upload image in datagridtemplatecolumn