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.