problem with data table
-
I am filling my datatable initially and databinding it to data gridview.code is written in button_click event.I am selecting an item from dropdownlist and when the button is clicked it is getting stored in the table.My problem is that the secondly selected item from dropdownlist is overwriting the first selected item instead of appending in the new row.I know some looping has to be done, but how and where? OleDbCommand pay_cmd2 = new OleDbCommand("select group_details.Group,description_details.Description,description_details.Unit_price from group_details,description_details where description_details.Description='" + descrptndpdnlt .SelectedItem .Value + "' AND group_details.Group_id=(select Group_id from description_details where Description='" + descrptndpdnlt .SelectedItem .Value + "')", con2); This is my code da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); DataTable pay_dt=ds_pay .Tables ["details"]; con2.Close(); GridView2.DataSource = pay_dt; GridView2.DataBind();
-
I am filling my datatable initially and databinding it to data gridview.code is written in button_click event.I am selecting an item from dropdownlist and when the button is clicked it is getting stored in the table.My problem is that the secondly selected item from dropdownlist is overwriting the first selected item instead of appending in the new row.I know some looping has to be done, but how and where? OleDbCommand pay_cmd2 = new OleDbCommand("select group_details.Group,description_details.Description,description_details.Unit_price from group_details,description_details where description_details.Description='" + descrptndpdnlt .SelectedItem .Value + "' AND group_details.Group_id=(select Group_id from description_details where Description='" + descrptndpdnlt .SelectedItem .Value + "')", con2); This is my code da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); DataTable pay_dt=ds_pay .Tables ["details"]; con2.Close(); GridView2.DataSource = pay_dt; GridView2.DataBind();
Hello I have no experience with datagrid But for DataGridView I'm sure about TWO think 1 : you must set the datasource to null before to reassign it GridView2.DataSource = null; GridView2.DataSource = pay_dt; 2 : this is not necessary : GridView2.DataBind();