Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

longtext column problem (2 replies)

$
0
0
Hi,
when reading data from a table with a LONGTEXT column, the MaxLength property of this DataColumn is set to 0 - resulting in a ConstraintException. I did not found a solution or even anyone other having this problem. Am I missing something?

Olaf

version: mysql-connector-net-6.7.4

Code:
Dim connectionString As String = "Server=myserver;Uid=myuser;Pwd=12345;Database=test;"
Using con As New MySqlConnection(connectionString)
con.Open()
Using cmd = con.CreateCommand
cmd.CommandText = _
"DROP TABLE IF EXISTS testtable;" & vbCrLf &
"CREATE TABLE testtable (" & vbCrLf &
" longtextcolumn longtext" & vbCrLf &
");" & vbCrLf &
"INSERT INTO testtable (longtextcolumn) VALUES ('long text 1');" & vbCrLf &
"INSERT INTO testtable (longtextcolumn) VALUES ('long text 2');" & vbCrLf &
"INSERT INTO testtable (longtextcolumn) VALUES ('long text 3');" & vbCrLf &
"INSERT INTO testtable (longtextcolumn) VALUES ('long text 4');" & vbCrLf &
"INSERT INTO testtable (longtextcolumn) VALUES ('long text 5');"
cmd.ExecuteNonQuery()
End Using

Using cmd = con.CreateCommand
Dim sql = "SELECT * FROM testtable;"
cmd.CommandText = sql
Using reader = cmd.ExecuteReader
Dim dt As New DataTable()
Try
dt.Load(reader)
Catch ex As ConstraintException
If dt.HasErrors Then
Console.WriteLine("")
For Each errorRow In dt.GetErrors()
Console.WriteLine("RowError: {0}", errorRow.RowError)
Next
End If
End Try

Console.WriteLine("")
Console.WriteLine("{0} rows received:", dt.Rows.Count)

For i = 0 To dt.Rows.Count - 1
Console.WriteLine("row # {0}: '{1}'", i, dt.Rows(i).Item(0))
Next

Console.WriteLine("")
Console.WriteLine("MaxLength of column {0}: {1}", dt.Columns(0).ColumnName, dt.Columns(0).MaxLength)
Console.WriteLine("")

End Using
End Using

End Using
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
Console.WriteLine("Press ENTER to exit...")
Console.ReadLine()


Results:
RowError: Column 'longtextcolumn' überschreitet das MaxLength-Limit.
RowError: Column 'longtextcolumn' überschreitet das MaxLength-Limit.
RowError: Column 'longtextcolumn' überschreitet das MaxLength-Limit.
RowError: Column 'longtextcolumn' überschreitet das MaxLength-Limit.
RowError: Column 'longtextcolumn' überschreitet das MaxLength-Limit.
5 rows received:
row # 0: 'long text 1'
row # 1: 'long text 2'
row # 2: 'long text 3'
row # 3: 'long text 4'
row # 4: 'long text 5'
MaxLength of column longtextcolumn: 0

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>