Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if (pay_typeComboBoxEdit.Text == "راتب")
{
paidMoneySpinEdit.ReadOnly = true;
paidMoneySpinEdit.Value = Convert.ToDecimal(PROCESS.GET_Salary(emp_idComboBoxEdit.Text, dateDateEdit.DateTime).Rows[0][0].ToString());
}
else
{
paidMoneySpinEdit.ReadOnly = false;
paidMoneySpinEdit.Value = 0;
}

What I have tried:

show this error when run the form project in C#
Posted
Updated 27-Dec-17 23:34pm
Comments
[no name] 28-Dec-17 5:08am    
It means you don't have data in your DataTable. Debug your code and check ....Rows.Count. The value will be most probably 0

Validate the Index before accessing it from the collection.

paidMoneySpinEdit.ReadOnly = true;
         DataTable dt = PROCESS.GET_Salary(emp_idComboBoxEdit.Text, dateDateEdit.DateTime);
         if(dt!= null && dt.Rows.Count>0 && dt.Columns.Count>0) { // validate the collection
         paidMoneySpinEdit.Value = Convert.ToDecimal(dt.Rows[0][0].ToString());
         }
 
Share this answer
 
The error is pretty explicit:
There is no row at position 0.

That means that whatever PROCESS.GET returns, it has no rows. That may be by design: if there is no data which matches your criteria (and I assume that's what the second parameter is for) then it can;t return any row info.

I'd suggest that you check the rows count and do something if there are no matches:
var data = PROCESS.GET_Salary(emp_idComboBoxEdit.Text, dateDateEdit.DateTime);
if (data.Rows.Count > 0)
   {
   paidMoneySpinEdit.Value = Convert.ToDecimal(data.Rows[0][0].ToString());
   }
else
   {
   ...  Up to you
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900