Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:02:40+00:00 2026-05-15T10:02:40+00:00

i am using database with table RESUME and column PageIndex in it which type

  • 0

i am using database with table RESUME and column PageIndex in it which type is number in database but when i want to store this PageIndex value to an integer i get exception error

Specified cast is not valid.

here is the code

string sql;
string conString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\\Deliverable4.accdb";
protected OleDbConnection rMSConnection;
protected OleDbDataAdapter rMSDataAdapter;
protected DataSet dataSet;
protected DataTable dataTable;
protected DataRow dataRow;

on Button Click

sql = "select PageIndex from RESUME";
rMSConnection = new OleDbConnection(conString);
rMSDataAdapter = new OleDbDataAdapter(sql, rMSConnection);
dataSet = new DataSet("pInDex");
rMSDataAdapter.Fill(dataSet, "RESUME");

dataTable = dataSet.Tables["RESUME"];

int pIndex =
(int)dataTable.Rows[0][0];

rMSConnection.Close();

if (pIndex == 0)
{            
    Response.Redirect("Create Resume-1.aspx");
}
else if (pIndex == 1)
{            
    Response.Redirect("Create Resume-2.aspx");
}
else if (pIndex == 2)
{          
        Response.Redirect("Create Resume-3.aspx");
    }
}

i am getting error in this line

int pIndex = (int)dataTable.Rows[0][0];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:02:40+00:00Added an answer on May 15, 2026 at 10:02 am

    May I very humbly suggest a different way of doing this?:

    string conString = "...";  // <-- your connection string
    
    using (IDbConnection connection = new OleDbConnection(conString))
    {   // ^^^ interface type makes your code less dependent on a particular backend!
        connection.Open();
        try
        {
            using (IDbCommand command = connection.CreateCommand())
            {   // ^^^ ditto
                command.CommandText = "SELECT PageIndex FROM RESUME";
                object scalar = command.ExecuteScalar();
                // ^ ExecuteScalar reads the first value in the first column
                //   of the result set; or returns null if it fails to do so.
    
                if (scalar == null) throw ...;  // unexpected result from database!
                if (scalar == DBNull.Value) throw ...;  // ditto!?
    
                int pIndex = (int)scalar;
    
                switch (pIndex)
                {
                    case 0:  Response.Redirect("Create Resume-1.aspx"); break;
                    case 1:  Response.Redirect("Create Resume-2.aspx"); break;
                    case 2:  Response.Redirect("Create Resume-3.aspx"); break;
                    default: throw ...;  // unexpected result from database!?
                }
            }
        }
        finally
        {
            connection.Close();  // (will execute even when exceptions are thrown!)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a database to store date and want a single column returned
I have a database table using an enum. This is already working with hibernate
I want to make custom select from the database table using Linq. We use
My database table have a Timestamp column named as inTime and i am using
I have a database table with some rows that I want to fetch using
I want to fetch the last result in MySQL database table using PHP. How
I am trying to create a database table using PostgreSQL but I am unable
I want to create some distributed mutual exclusion using a database table. It would
Using Access Database Table ID Time 001 100000 001 100005 001 103000 001 102500
I am trying to insert into my database table using the database helper class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.