0

I have data Column type: system.int32 and I want to save a normal Integer value in it.

  • For Example

    I want to save the Integer "1" into a system.int32 column.

  • Then a exception is thrown which says

"The Value is more then The Max.length of this column".

Got any one an Idea?

Edit:

Here is the code:

Dim reader As OleDbDataReader = Nothing
    Dim schemaTable As DataTable = New DataTable
    Dim dt As DataTable = New DataTable




        sql = "SELECT * from " & TabName
        mCmd.CommandText = sql
        reader = mCmd.ExecuteReader(CommandBehavior.KeyInfo)
        schemaTable = reader.GetSchemaTable()

        Dim dc As DataColumn
        Dim key As Integer = 0
        Dim ColumnOrdinal As Integer
        For Each myField As DataRow In schemaTable.Rows
            dc = New DataColumn
            For Each myProperty As DataColumn In schemaTable.Columns
                ' Console.WriteLine(myProperty.ColumnName + " = " + myField(myProperty).ToString())
                System.Diagnostics.Debug.WriteLine(myProperty.ColumnName + " = " + myField(myProperty).ToString())
                If myProperty.ColumnName = "ColumnName" Then dc.ColumnName = myField(myProperty)
                If myProperty.ColumnName = "ColumnOrdinal" Then ColumnOrdinal = myField(myProperty)
                If myProperty.ColumnName = "DataType" Then dc.DataType = myField(myProperty)
                If myProperty.ColumnName = "IsAutoIncrement" Then dc.AutoIncrement = myField(myProperty)
                If myProperty.ColumnName = "ReadOnly" Then dc.ReadOnly = myField(myProperty)
                If myProperty.ColumnName = "IsUnique" Then dc.Unique = myField(myProperty)
                If myProperty.ColumnName = "ColumnSize" Then dc.MaxLength = myField(myProperty)
                If myProperty.ColumnName = "IsKey" AndAlso myField(myProperty) = True Then key = ColumnOrdinal
                ' System.Diagnostics.Debug.WriteLine(myProperty.DataType)
            Next
            If dc.AutoIncrement = False Then
                dt.Columns.Add(dc)
            End If
        Next

When at this line myProperty pases datatyp Int32

 If myProperty.ColumnName = "DataType" Then dc.DataType = myField(myProperty)

I get the exception during filling the datatable which I created above. Here is the code:

  Dim reader As StreamReader = Nothing
  reader = New StreamReader(File, Encoding.Default)

 Do Until reader.EndOfStream                         
     Textzeile = reader.ReadLine()
     spalten = reader.ReadLine().Split(";"c) 
     Dim dr As DataRow = Nothing 
     dr =dt.NewRow() 
     For i As Integer = 0 To dt.Columns.Count - 1
           dr(i) = spalten(i)
     Next
     dt.Rows.Add(dr)  
     .
     .
     .

At this line the exception is thrown

dt.Rows.Add(dr) 

Edit2: Problem solved. As we commented out Columnsize it worked.I would love to know why it works now. Columnsize was inizialized with 4 as it did not work.

steve
  • 123
  • 1
  • 14
  • 1
    It sounds like you are trying to save the value to the wrong thing. You should add your code containing where/how you are trying to save this integer – Sayse Jul 10 '14 at 07:44
  • 2
    Question without code, question without answer... – Nicolas Henrard Jul 10 '14 at 07:49
  • Thx for the Update of answer. I asked this question in place of a friend of mine. But i will try to add the code. – steve Jul 10 '14 at 08:03
  • Where's the table definition? Sounds like if you can't insert a `1` into an integer column, then that column isn't numeric! Or is it as simple as changing to `If myProperty.ColumnName = "DataType" Then dc.DataType = CInt(myField(myProperty))` ?? – Grim Jul 10 '14 at 11:02

0 Answers0