I arranging and extracting data from database to the datagrid, i am trying to custom the column and rows to display the data desired, through the looping i tried to match the data from the one of the datatable to get another data to fill into the datagrid, unfortunately i keep getting "There is no row at position 1 error". I've attached attachment to illustrate the problems faced by me.
I've gone through some of the posts in stackoverflow to resolve the problems,i can't find the problems. 1. Error There is no row at position 1 2. there is no row at position 1
- private void generate_view1(DataTable search_data1)
- {
- DataTable sample_data1 = new DataTable();
- sample_data1 = search_data1.Copy();
- sample_data1.Columns.Add("Item_Number");
- sample_data1.Columns.Add("Min_Tolerance");
- sample_data1.Columns.Add("Max_Tolerance");
-
-
- var database_select = new DatabaseSelect();
- string OrderNo = Order_NO.Text.ToString();
- DataTable result_data = new DataTable();
- result_data = database_select.LoadTable_DOHEAD(OrderNo);
-
- string SalesNO = result_data.Rows[0]["EAORNO"].ToString();
- string Del_index = result_data.Rows[0]["EADLIX"].ToString();
-
- var database_select1 = new DatabaseSelect();
- DataTable result_weight = new DataTable();
- result_weight = database_select.LoadTable_MITTRA(SalesNO, Del_index);
-
-
- dataGrid1.ItemsSource = null;
- dataGrid1.ItemsSource = sample_data1.DefaultView;
- DataGridTextColumn Weight1 = new DataGridTextColumn();
- dataGrid1.DisplayMemberPath = sample_data1.Columns["MTTRQT"].ToString();
-
- Decimal sum = Convert.ToDecimal(sample_data1.Compute("SUM(MTTRQT)", string.Empty));
-
- Weight.Text = (sum * -1).ToString();
-
- for (int i = 0; i < sample_data1.Rows.Count; i++)
- {
- string itemcode = sample_data1.Rows[i]["MTITNO"].ToString();
- String ItemNumber = result_weight.Rows[i]["MTITNO"].ToString();
-
- if (itemcode != " ")
- {
- sample_data1.Rows[i]["Item_Number"] = result_weight.Rows[i]["MTITNO"].ToString();
-
- var database_select2 = new DatabaseSelect();
-
- DataTable result_tolerance = new DataTable();
- result_tolerance = database_select.LoadUser_Tolerance(ItemNumber);
- sample_data1.Rows[i]["Min_Tolerance"] = result_tolerance.Rows[i]["Min_Tol"].ToString();
- string MINTOL = result_tolerance.Rows[i]["Min_Tol"].ToString();
- MessageBox.Show(MINTOL);
-
- }
-
- }
LoadUser_Tolerance variable query( i am trying to select min tolerance from this query to insert it into my datagrid) For the results desired( you can refer the illustrations above), i only having this issues whenever i tried to get MinTolerance to display in my DataGrid. i can't figure out how to make this right.
- public DataTable LoadUser_Tolerance(string ItemNO)
- {
- OdbcConnection conn = new OdbcConnection();
- conn.ConnectionString = ConString;
- conn.Open();
- CmdString = "SELECT Item_NO, Min_Tol, Max_Tol FROM MasTolerance where Item_NO ='" + ItemNO + "'";
- OdbcCommand cmd = new OdbcCommand(CmdString, conn);
- OdbcDataAdapter sda = new OdbcDataAdapter(cmd);
- DataTable dt = new DataTable("MasTolerance");
- sda.Fill(dt);
- return dt;
- }
Debugging Attempts Tried.
- if (result_tolerance.Rows.Count > i)
- {
- sample_data1.Rows[i]["Min_Tolerance"] = result_tolerance.Rows[i]["Min_Tol"].ToString();
- string MINTOL = result_tolerance.Rows[i]["Min_Tol"].ToString();
- MessageBox.Show(MINTOL + i);
- }
- else
- {
- MessageBox.Show("Error");
-
- }
Sorry to make the whole thing this long, but I have no choice.