Exception throws There is no row at position 0

Posted by Nimantha Prasad on Stack Overflow See other posts from Stack Overflow or by Nimantha Prasad
Published on 2012-10-19T04:51:12Z Indexed on 2012/10/19 5:01 UTC
Read the original article Hit count: 190

Filed under:
|

I wanted to check user is valid or not.it gives me the exception,When user valid it's working without issue,But if user invalid there's some issue.

Exception is : There is no row at position 0

Here is the part of the code,

 public bool CheckUserExistAndReporter(string user)
{
    int reporterDnnId = -1;
    SMSFunctionController mysms = new SMSFunctionController();
    DataSet uds = mysms.GetUsersUnitByUserName(user);

    reporterDnnId = Convert.ToInt32(uds.Tables[0].Rows[0]["DnnUserID"]);
    if (reporterDnnId > 0)
    {
        bool isValidUser = true;
        return isValidUser;
    }
    //else
    //{
        //bool isValidUser =false;
        //return isValidUser;
   // }
    return false;
}

Then i call thatone here.

                if (!CheckUserExistAndReporter(user))
                {
                    ErrorLog(messageIn);
                    msgOut = "ugyldig Bruker";//Invalid User.

                }

what is the error ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#-4.0