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. Compiler error

Compiler error

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 5 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.
  • N Offline
    N Offline
    NewToAspDotNet
    wrote on last edited by
    #1

    Hi All, Im trying to run this code: foreach (DataRow dr in ds.Tables["table1"].Rows) { if (dr[1].ToString() == "f") { dr[1].ToString() = "finish"; } else { dr[1].ToString() = "not finish"; } } But im getting the error: The left-hand side of an assignment must be a variable, property or indexer Could'nt find anything on google that solves this. Anyone a idea? Thanx

    G M J L 4 Replies Last reply
    0
    • N NewToAspDotNet

      Hi All, Im trying to run this code: foreach (DataRow dr in ds.Tables["table1"].Rows) { if (dr[1].ToString() == "f") { dr[1].ToString() = "finish"; } else { dr[1].ToString() = "not finish"; } } But im getting the error: The left-hand side of an assignment must be a variable, property or indexer Could'nt find anything on google that solves this. Anyone a idea? Thanx

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      You are assigning a value to a result of a function.

      #region signature my articles #endregion

      1 Reply Last reply
      0
      • N NewToAspDotNet

        Hi All, Im trying to run this code: foreach (DataRow dr in ds.Tables["table1"].Rows) { if (dr[1].ToString() == "f") { dr[1].ToString() = "finish"; } else { dr[1].ToString() = "not finish"; } } But im getting the error: The left-hand side of an assignment must be a variable, property or indexer Could'nt find anything on google that solves this. Anyone a idea? Thanx

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        It is generally better to convert from object to a concrete type by casting, if you know what type an expression is, than to use a conversion function. I would write this as

        foreach (DataRow dr in ds.Tables["table1"].Rows)
        {
        if ( (string)dr[1] == "f" )
        {
        dr[1] = "finish";
        }
        else
        {
        dr[1] = "not finish";
        }
        }

        DoEvents: Generating unexpected recursion since 1991

        1 Reply Last reply
        0
        • N NewToAspDotNet

          Hi All, Im trying to run this code: foreach (DataRow dr in ds.Tables["table1"].Rows) { if (dr[1].ToString() == "f") { dr[1].ToString() = "finish"; } else { dr[1].ToString() = "not finish"; } } But im getting the error: The left-hand side of an assignment must be a variable, property or indexer Could'nt find anything on google that solves this. Anyone a idea? Thanx

          J Offline
          J Offline
          Jaiprakash M Bankolli
          wrote on last edited by
          #4

          Remove the toString() from dr[1].ToString() and dr[1].ToString()... Everything will work fine

          Regards, Jaiprakash M Bankolli jaiprakash.bankolli@gmail.com My Blog Suggestions for me

          1 Reply Last reply
          0
          • N NewToAspDotNet

            Hi All, Im trying to run this code: foreach (DataRow dr in ds.Tables["table1"].Rows) { if (dr[1].ToString() == "f") { dr[1].ToString() = "finish"; } else { dr[1].ToString() = "not finish"; } } But im getting the error: The left-hand side of an assignment must be a variable, property or indexer Could'nt find anything on google that solves this. Anyone a idea? Thanx

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi Justim, this is not a compiler error at all; at best it is a compiler-generated error message, due to a Justim error. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            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