problem with int32 field and long for dataGrid
-
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?
-
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?
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
-
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?
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 -
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?
Here are the columns. I think I can solvemy problems by changing my phone and cell to strings. I did leavethe collumn names out.
-
Here are the columns. I think I can solvemy problems by changing my phone and cell to strings. I did leavethe collumn names out.
how do I format a phone number on output for display in a dataGrid? Lets say I want it like this.
(909)554-2574