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. problem with int32 field and long for dataGrid

problem with int32 field and long for dataGrid

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

    I am trying to put some info from the database and datatable into a data grid and I get an error on the phone number fields when trying to display the info in the dataGrid control. Here is the error I get. It says it can't store the info in the column. The type is Int 32, expecting Int32. In the database in this column I am using a bigint in sql server express 2005. Here is my code.

    Dim dt As New DataTable()        
    Dim dr As DataRow
    
    For Each row As DataRow In dtStud.Rows            
    dr = dt.NewRow()            
    dr(0) = row("stud_name")            
    dr(1) = row("stud_par_name")            
    dr(2) = row("stud_id")            
    
    ' get student instruments            
    Call studentInstruments(Convert.ToInt32(row("stud_id")))            
    
    ' 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(row("less_instrument"))                
     End If            
    Next            
    
    dr(3) = row("stud_phone")            
    dr(4) = row("stud_cell")            
    dr(5) = strInst            
    
    dt.Rows.Add(dr)        
    
    Next
    

    Can anyone tell me why it expects int32 when I am using a Long for the data table column. The error says the following:

    Value was either too small or large for an int32. Couldn't store <9098791232>in stud_phone column. Expected type is Int32.

    stud_phone is the name of the database field. I get this error on program start up which means it is in sub loadStudentList(). Do you thinkitmight help to convert the vlue from the database to a string?

    M D A 3 Replies Last reply
    0
    • A AAGTHosting

      I am trying to put some info from the database and datatable into a data grid and I get an error on the phone number fields when trying to display the info in the dataGrid control. Here is the error I get. It says it can't store the info in the column. The type is Int 32, expecting Int32. In the database in this column I am using a bigint in sql server express 2005. Here is my code.

      Dim dt As New DataTable()        
      Dim dr As DataRow
      
      For Each row As DataRow In dtStud.Rows            
      dr = dt.NewRow()            
      dr(0) = row("stud_name")            
      dr(1) = row("stud_par_name")            
      dr(2) = row("stud_id")            
      
      ' get student instruments            
      Call studentInstruments(Convert.ToInt32(row("stud_id")))            
      
      ' 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(row("less_instrument"))                
       End If            
      Next            
      
      dr(3) = row("stud_phone")            
      dr(4) = row("stud_cell")            
      dr(5) = strInst            
      
      dt.Rows.Add(dr)        
      
      Next
      

      Can anyone tell me why it expects int32 when I am using a Long for the data table column. The error says the following:

      Value was either too small or large for an int32. Couldn't store <9098791232>in stud_phone column. Expected type is Int32.

      stud_phone is the name of the database field. I get this error on program start up which means it is in sub loadStudentList(). Do you thinkitmight help to convert the vlue from the database to a string?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I would think you would always store a phone number as string (makes this problem go away) and caters for spaces, - etc You will need to change it at the table definition, always try and avoid format changes during processing

      1 Reply Last reply
      0
      • A AAGTHosting

        I am trying to put some info from the database and datatable into a data grid and I get an error on the phone number fields when trying to display the info in the dataGrid control. Here is the error I get. It says it can't store the info in the column. The type is Int 32, expecting Int32. In the database in this column I am using a bigint in sql server express 2005. Here is my code.

        Dim dt As New DataTable()        
        Dim dr As DataRow
        
        For Each row As DataRow In dtStud.Rows            
        dr = dt.NewRow()            
        dr(0) = row("stud_name")            
        dr(1) = row("stud_par_name")            
        dr(2) = row("stud_id")            
        
        ' get student instruments            
        Call studentInstruments(Convert.ToInt32(row("stud_id")))            
        
        ' 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(row("less_instrument"))                
         End If            
        Next            
        
        dr(3) = row("stud_phone")            
        dr(4) = row("stud_cell")            
        dr(5) = strInst            
        
        dt.Rows.Add(dr)        
        
        Next
        

        Can anyone tell me why it expects int32 when I am using a Long for the data table column. The error says the following:

        Value was either too small or large for an int32. Couldn't store <9098791232>in stud_phone column. Expected type is Int32.

        stud_phone is the name of the database field. I get this error on program start up which means it is in sub loadStudentList(). Do you thinkitmight help to convert the vlue from the database to a string?

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

        The code you posted doesn't create any columns in this new DataTable, so I'm assuming you left it out. What's the column type you created?? You also shouldn't be storing phone numbers as a number. They should be stored as a string.

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

        1 Reply Last reply
        0
        • A AAGTHosting

          I am trying to put some info from the database and datatable into a data grid and I get an error on the phone number fields when trying to display the info in the dataGrid control. Here is the error I get. It says it can't store the info in the column. The type is Int 32, expecting Int32. In the database in this column I am using a bigint in sql server express 2005. Here is my code.

          Dim dt As New DataTable()        
          Dim dr As DataRow
          
          For Each row As DataRow In dtStud.Rows            
          dr = dt.NewRow()            
          dr(0) = row("stud_name")            
          dr(1) = row("stud_par_name")            
          dr(2) = row("stud_id")            
          
          ' get student instruments            
          Call studentInstruments(Convert.ToInt32(row("stud_id")))            
          
          ' 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(row("less_instrument"))                
           End If            
          Next            
          
          dr(3) = row("stud_phone")            
          dr(4) = row("stud_cell")            
          dr(5) = strInst            
          
          dt.Rows.Add(dr)        
          
          Next
          

          Can anyone tell me why it expects int32 when I am using a Long for the data table column. The error says the following:

          Value was either too small or large for an int32. Couldn't store <9098791232>in stud_phone column. Expected type is Int32.

          stud_phone is the name of the database field. I get this error on program start up which means it is in sub loadStudentList(). Do you thinkitmight help to convert the vlue from the database to a string?

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

          Here are the columns. I think I can solvemy problems by changing my phone and cell to strings. I did leavethe collumn names out.

          A 1 Reply Last reply
          0
          • A AAGTHosting

            Here are the columns. I think I can solvemy problems by changing my phone and cell to strings. I did leavethe collumn names out.

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

            how do I format a phone number on output for display in a dataGrid? Lets say I want it like this.

            (909)554-2574

            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