error in comparing (netsed if else logic)

Posted by Vijaym.H under C# on 1/14/2015 | Points: 10 | Views : 984 | Status : [Member] | Replies : 1
hi, i am getting problem in validation (selecting maxumim registrationno from table),after we have to compare new registrationno can't be greater than old registration no. (attached Screen shot)

I am getting errors like:"there is no row at position 0","db casting cant be done".

my Code:

if (!String.IsNullOrEmpty(pract.OldRegistrationNo))
{
pract.RegistrationNo = pract.OldRegistrationNo;
}
else
{
pract.RegistrationNo = Request.Form["txtRegNo"];
}

pract.RegistrationDate = Request.Form["Text1"];
DataTable dt1 = new DataTable();
pract.OldRegistrationNo = Request.Form["txtoldregnumber"]; //my code start from here
db.CommandText = "select max (cast(RegistrationNo as int)) as highest from tbl_practitioner
db.CommandType = CommandType.Text;
dt1 = db.ReturnDataTable();


if (Convert.ToInt32(dt1.Rows[0]["highest"]) < Convert.ToInt32(Request.Form["txtoldregnumber"]))
{

NewPID = pract.Add();
}
else
{
Response.Write("<script>alert('Not valid RegistratrionNo');</script>");
//Response.End();

}
}




Responses

Posted by: Bandi on: 1/16/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://www.wenda.io/questions/2017513/exception-throws-there-is-no-row-at-position-0.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Vijaym.H, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response