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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How can I change these VB.net to C# codes?

How can I change these VB.net to C# codes?

Scheduled Pinned Locked Moved C#
csharphelpquestion
8 Posts 5 Posters 1 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.
  • A Offline
    A Offline
    ATC
    wrote on last edited by
    #1

    I have the following VB.net codes: da = New OleDbDataAdapter(strSQL, dbConn) dt = New DataTable da.Fill(dt) Dim rows As DataRow cnt = dt.Rows.Count() If cnt > 0 Then For Each rows In dt.Rows Total += rows.Item("Total") Next End If I changed to these C#: da = new OleDbDataAdapter(strSQL, CGlobal.dbConn); dt = new DataTable(); da.Fill(dt); cnt = dt.Rows.Count; DataRow rows = default(DataRow); if (cnt > 0) { foreach (rows in dt.Rows) Total += rows.Item("Total"); } And I have the error in in above, can anyone help to correct my C#? Thank :doh:

    P P D 3 Replies Last reply
    0
    • A ATC

      I have the following VB.net codes: da = New OleDbDataAdapter(strSQL, dbConn) dt = New DataTable da.Fill(dt) Dim rows As DataRow cnt = dt.Rows.Count() If cnt > 0 Then For Each rows In dt.Rows Total += rows.Item("Total") Next End If I changed to these C#: da = new OleDbDataAdapter(strSQL, CGlobal.dbConn); dt = new DataTable(); da.Fill(dt); cnt = dt.Rows.Count; DataRow rows = default(DataRow); if (cnt > 0) { foreach (rows in dt.Rows) Total += rows.Item("Total"); } And I have the error in in above, can anyone help to correct my C#? Thank :doh:

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      When you use a foreach, you need to say what the type is; hence foreach (DataRow rows in dt.Rows).

      Deja View - the feeling that you've seen this post before.

      My blog | My articles | MoXAML PowerToys

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        When you use a foreach, you need to say what the type is; hence foreach (DataRow rows in dt.Rows).

        Deja View - the feeling that you've seen this post before.

        My blog | My articles | MoXAML PowerToys

        A Offline
        A Offline
        ATC
        wrote on last edited by
        #3

        I did try before & had 2 errors: cnt = dt.Rows.Count; DataRow rows = default(DataRow); foreach (DataRow rows in dt.Rows) Total += rows.Item("Total"); By any chance you know how to fix them? What I need to get values from column 'Total' of those selected row Thanks :doh:

        D P 2 Replies Last reply
        0
        • A ATC

          I did try before & had 2 errors: cnt = dt.Rows.Count; DataRow rows = default(DataRow); foreach (DataRow rows in dt.Rows) Total += rows.Item("Total"); By any chance you know how to fix them? What I need to get values from column 'Total' of those selected row Thanks :doh:

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          rows is already defined in the line above the foreach. Why not use row seing as it will represent just one row.

          foreach (DataRow row in dt.Rows)
          Total += row.Item("Total");

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

          A 1 Reply Last reply
          0
          • D DaveyM69

            rows is already defined in the line above the foreach. Why not use row seing as it will represent just one row.

            foreach (DataRow row in dt.Rows)
            Total += row.Item("Total");

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            A Offline
            A Offline
            ATC
            wrote on last edited by
            #5

            I did try & have small error from Item, but I think I can fix it by using array for the column. Thanks,

            1 Reply Last reply
            0
            • A ATC

              I have the following VB.net codes: da = New OleDbDataAdapter(strSQL, dbConn) dt = New DataTable da.Fill(dt) Dim rows As DataRow cnt = dt.Rows.Count() If cnt > 0 Then For Each rows In dt.Rows Total += rows.Item("Total") Next End If I changed to these C#: da = new OleDbDataAdapter(strSQL, CGlobal.dbConn); dt = new DataTable(); da.Fill(dt); cnt = dt.Rows.Count; DataRow rows = default(DataRow); if (cnt > 0) { foreach (rows in dt.Rows) Total += rows.Item("Total"); } And I have the error in in above, can anyone help to correct my C#? Thank :doh:

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              ATC wrote:

              have the error in in above

              Be more descriptive :|

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              1 Reply Last reply
              0
              • A ATC

                I have the following VB.net codes: da = New OleDbDataAdapter(strSQL, dbConn) dt = New DataTable da.Fill(dt) Dim rows As DataRow cnt = dt.Rows.Count() If cnt > 0 Then For Each rows In dt.Rows Total += rows.Item("Total") Next End If I changed to these C#: da = new OleDbDataAdapter(strSQL, CGlobal.dbConn); dt = new DataTable(); da.Fill(dt); cnt = dt.Rows.Count; DataRow rows = default(DataRow); if (cnt > 0) { foreach (rows in dt.Rows) Total += rows.Item("Total"); } And I have the error in in above, can anyone help to correct my C#? Thank :doh:

                D Offline
                D Offline
                Dave Doknjas
                wrote on last edited by
                #7

                da = new OleDbDataAdapter(strSQL, dbConn); dt = new DataTable(); da.Fill(dt); DataRow rows = null; cnt = dt.Rows.Count(); if (cnt > 0) { foreach (DataRow rowsWithinLoop in dt.Rows) { rows = rowsWithinLoop; Total += rowsWithinLoop["Total"]; } } David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB & C# to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI

                1 Reply Last reply
                0
                • A ATC

                  I did try before & had 2 errors: cnt = dt.Rows.Count; DataRow rows = default(DataRow); foreach (DataRow rows in dt.Rows) Total += rows.Item("Total"); By any chance you know how to fix them? What I need to get values from column 'Total' of those selected row Thanks :doh:

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  Item is an indexed property, so you use

                  Total += rows.Item["Total"];

                  C# uses square brackets [ and ] for indexers.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles | MoXAML PowerToys

                  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