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
lye nian
NA
7
8k
How to fix “There is no row at position 1”
Apr 24 2019 10:18 PM
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();
//******Problems occur in below this part*********//
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);
//** i've include my loadUser Tolerance query in here as well***//
sample_data1.Rows[i][
"Min_Tolerance"
] = result_tolerance.Rows[i][
"Min_Tol"
].ToString();
//*** this is the line where i face the problems***//
string
MINTOL = result_tolerance.Rows[i][
"Min_Tol"
].ToString();
//*** i've put in this to illustrate the problems**//
MessageBox.Show(MINTOL);
//*** i've put in this to illustrate the problems**//
}
}
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"
);
//** i can display the Item number in row 1, but Min tolerance for the Row 1 can't be display**//
}
Sorry to make the whole thing this long, but I have no choice.
Reply
Answers (
5
)
Why i should event if i can reference to a method through a?
Remove Cookies of webBrowser control in Winform c# .net