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. Visual Basic
  4. Can't find column 1 in dataTable that populates dataview then datagrid

Can't find column 1 in dataTable that populates dataview then datagrid

Scheduled Pinned Locked Moved Visual Basic
help
4 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.
  • A Offline
    A Offline
    AAGTHosting
    wrote on last edited by
    #1

    Why do I get the error can't find column 1.

    dtStudList = generalQuery(int)
    
            dt.Columns.Add(New DataColumn("Student Name", GetType(String)))
            'dt.Columns.Add(New DataColumn("Parent Name", GetType(String)))
            'dt.Columns.Add(New DataColumn("Phone", GetType(String)))
            'dt.Columns.Add(New DataColumn("Cell", GetType(String)))
            'dt.Columns.Add(New DataColumn("Instrument", GetType(String)))
    
            For Each row As DataRow In dtStudList.Rows
                dr = dt.NewRow()
                dr(0) = row("stud_name")
                dr(1) = row("stud_par_name")
                dr(2) = row("stud_id")
                dr(3) = row("stud_phone")
                dr(4) = row("stud_cell")
    
                ' get student instruments
                intStudList = Convert.ToInt32(row("stud_id"))
                tableName = "tbl_lessons"
                dtStudInst = generalQuery()
    
                ' create counter
                Dim intCount As Integer = 1
    
                For Each row2 As DataRow In dtStudInst.Rows
                    If intCount = 1 Then
                        strInst = Convert.ToString(row2("less_instrument"))
                    Else
                        strInst += ", " & Convert.ToString(row2("less_instrument"))
                    End If
                Next
    
                'dr(5) = strInst
                dt.Rows.Add(dr)
                intCount += 1
            Next
    
            Dim dgView As New DataView(dt)
            dgrStudList.DataSource = dgView
    
    D 1 Reply Last reply
    0
    • A AAGTHosting

      Why do I get the error can't find column 1.

      dtStudList = generalQuery(int)
      
              dt.Columns.Add(New DataColumn("Student Name", GetType(String)))
              'dt.Columns.Add(New DataColumn("Parent Name", GetType(String)))
              'dt.Columns.Add(New DataColumn("Phone", GetType(String)))
              'dt.Columns.Add(New DataColumn("Cell", GetType(String)))
              'dt.Columns.Add(New DataColumn("Instrument", GetType(String)))
      
              For Each row As DataRow In dtStudList.Rows
                  dr = dt.NewRow()
                  dr(0) = row("stud_name")
                  dr(1) = row("stud_par_name")
                  dr(2) = row("stud_id")
                  dr(3) = row("stud_phone")
                  dr(4) = row("stud_cell")
      
                  ' get student instruments
                  intStudList = Convert.ToInt32(row("stud_id"))
                  tableName = "tbl_lessons"
                  dtStudInst = generalQuery()
      
                  ' create counter
                  Dim intCount As Integer = 1
      
                  For Each row2 As DataRow In dtStudInst.Rows
                      If intCount = 1 Then
                          strInst = Convert.ToString(row2("less_instrument"))
                      Else
                          strInst += ", " & Convert.ToString(row2("less_instrument"))
                      End If
                  Next
      
                  'dr(5) = strInst
                  dt.Rows.Add(dr)
                  intCount += 1
              Next
      
              Dim dgView As New DataView(dt)
              dgrStudList.DataSource = dgView
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      AAGTHosting wrote:

      Why do I get the error can't find column 1.

      On which line does this error show up?? You do know that you commented out a bunch of Column.Add() statements near the top of your code snippet, right? Those columns aren't getting created.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        AAGTHosting wrote:

        Why do I get the error can't find column 1.

        On which line does this error show up?? You do know that you commented out a bunch of Column.Add() statements near the top of your code snippet, right? Those columns aren't getting created.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

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

        I know. I just need to know what I am doing wrong with the dataGrid. I commented those lnes out to see if any of the columns would be able to be found.

        D 1 Reply Last reply
        0
        • A AAGTHosting

          I know. I just need to know what I am doing wrong with the dataGrid. I commented those lnes out to see if any of the columns would be able to be found.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          OK. Again, on what line does the error occur??

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          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