Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Database access related issue

    Dear Sir,
    I have accessed one field from database with datareader.Now I want to check it and the accordinngly want to increase or decrease it.
    (e.g. If we got 4 from database and this 4 has been stored in the datareader object(e.g.dr[0] contains 4) now i want to check it aginst 5 if it is 5 then display 6).
    I tried below mentioned code for the same -
    SqlDataReader dr = null;
    dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {
    if (dr.GetInt32(0) == 5)
    {
    Response.Write("6");
    }
    }
    }

    But it is giving Exception in if condition is that Specified cast is not valid.
    How it is possible.
    Pls help me out.

    Thanks
    Abhishek .

  • #2
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this,

    SqlDataReader dr = null;
    dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {
    if (dr(0).tostring() == "5")
    {
    Response.Write("6");
    }
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •