0

Hi, i am trying to open a form from selected data in an earlier from. I use cust_id = grd_customer(0, current_row).Value to hold the value so that cust_id will open up a from that has a customer's details.

But i keep on getting Unhandled Exception of type 'System.IndexOutOfRangeException' that says, there is no row at position 0. And i dont understand the problem. Can anyone explain this?

command on frm_cust_details - > lbl_cid.Text = run_sql_query("SELECT * FROM TBL_CUSTOMER WHERE CUST_IC = '" & cust_id & "'").Rows(0).Item("CUST_ID")

Edited by nur faeza

3
Contributors
2
Replies
7
Views
1 Year
Discussion Span
Last Post by ZER09
0

That error would generally happen because the select statement has returned an empty set, which is why the row count is zero. Double check your sql statement is working as expected by running it directly against the database.

0

hericles is correct, it is returning an empty set, try to check "cust_id", it might be that the value of the cust_id is not in the database.

And could you do me a favor, please use parameterized query, that could solve many issue, that might be you will encounter in the future.

i will give you an example
rather that using like this

public DataTable run_sql_query(string query)
{
    ///code
}

do it like this

public DataTable run_sql_query(string parameterizedQuery, Dictionary<strin, object> paramters)
{
    ///code
    ///you can iterate on the dictionary
    ///and add the parameter value
}

that is just an example, you can make it better to fit in your preference.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.