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. General Programming
  3. C#
  4. Setting an instance object equal to my empty string.

Setting an instance object equal to my empty string.

Scheduled Pinned Locked Moved C#
databasequestion
3 Posts 3 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.
  • U Offline
    U Offline
    User 11249599
    wrote on last edited by
    #1

    I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.

    UserPass = reader["Password"].ToString();

    So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:

    SqlDataReader reader = myCommand.ExecuteReader();

    (myCommand is an SqlCommand obj)

    reader["Password"]

    Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:

    An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code

    It doesn't give much more detail other than that and I'm not entirely sure what's wrong.

    P S 2 Replies Last reply
    0
    • U User 11249599

      I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.

      UserPass = reader["Password"].ToString();

      So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:

      SqlDataReader reader = myCommand.ExecuteReader();

      (myCommand is an SqlCommand obj)

      reader["Password"]

      Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:

      An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code

      It doesn't give much more detail other than that and I'm not entirely sure what's wrong.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Nothing you provided looks obviously wrong. Which statement throws the Exception? We may need to see the query. And provide the code in proper order.

      1 Reply Last reply
      0
      • U User 11249599

        I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.

        UserPass = reader["Password"].ToString();

        So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:

        SqlDataReader reader = myCommand.ExecuteReader();

        (myCommand is an SqlCommand obj)

        reader["Password"]

        Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:

        An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code

        It doesn't give much more detail other than that and I'm not entirely sure what's wrong.

        S Offline
        S Offline
        Shweta N Mishra
        wrote on last edited by
        #3

        did you debug to identify on which line you had the issue?

        Mark the answer as accepted if that worked for you :). And for down-voters please specify the reason to improve the solution :).

        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