Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to remove System.InvalidCastException error?

how to remove System.InvalidCastException error?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netvisual-studiocomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sathyan_8294
    wrote on last edited by
    #1

    hai all, i am using .net 2005.i am doing my project in asp.net using c#.for my project back end is MS ACCESS 97. the following code is com = new OleDbCommand("select HolderNo,HolderName,DepartmentNo,mid(Appsetdata," + bb + ",2),JobTitle from holderdata where DepartmentNo <> '0000'", con); dr = com.ExecuteReader(); i1 = 0; while (dr.Read()) { holno[i1] = dr.GetString(0); holname[i1] = dr.GetString(1); dept[i1] = dr.GetString(2); appset_holder[i1] = Convert.ToInt16(dr.GetString(3)); jobtitle[i1] = dr.GetString(4); i1++; } dr.Close(); in the above code shown the error in jobtitle[i1] = dr.GetString(4); the following error were display, System.InvalidCastException: Specified cast is not valid. at System.Data.OleDb.ColumnBinding.ValueString() at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal) at _Default.emp_iterate() in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 182 at _Default.validate_main() in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 126 at _Default.SubmitImageButton_Click(Object sender, ImageClickEventArgs e) in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 101 how to solve the above error?thanks to all in advance.

    F 1 Reply Last reply
    0
    • S sathyan_8294

      hai all, i am using .net 2005.i am doing my project in asp.net using c#.for my project back end is MS ACCESS 97. the following code is com = new OleDbCommand("select HolderNo,HolderName,DepartmentNo,mid(Appsetdata," + bb + ",2),JobTitle from holderdata where DepartmentNo <> '0000'", con); dr = com.ExecuteReader(); i1 = 0; while (dr.Read()) { holno[i1] = dr.GetString(0); holname[i1] = dr.GetString(1); dept[i1] = dr.GetString(2); appset_holder[i1] = Convert.ToInt16(dr.GetString(3)); jobtitle[i1] = dr.GetString(4); i1++; } dr.Close(); in the above code shown the error in jobtitle[i1] = dr.GetString(4); the following error were display, System.InvalidCastException: Specified cast is not valid. at System.Data.OleDb.ColumnBinding.ValueString() at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal) at _Default.emp_iterate() in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 182 at _Default.validate_main() in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 126 at _Default.SubmitImageButton_Click(Object sender, ImageClickEventArgs e) in c:\Documents and Settings\sabari\My Documents\Visual Studio 2005\Projects\styrisact1\Default.aspx.cs:line 101 how to solve the above error?thanks to all in advance.

      F Offline
      F Offline
      firozu
      wrote on last edited by
      #2

      According to the error text, I think there may be a problem with appset_holder[i1] = Convert.ToInt16(dr.GetString(3)) this line of code. Maybe the value returning from database is null or empty and you are trying to convert it to Int16. Check the value in DB. Hope this helps.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups