DataSet NewRow() error using VB.NET 2003

  • Thread starter Thread starter Mika M
  • Start date Start date
M

Mika M

Hello!

I'm testing MySQL-database version 4.0.18, which contains table column
'ArticleNr' and data type is varchar length 40.

Connection is made using ODBC ConnectionString like ...

"DRIVER={MySQL ODBC 3.51
Driver};Server=localhost;Database=MyTesting;uid=XXX;pwd=ZZZ"

DataSet contains two tables Master and Child, and Relation between then is
defined like ...

ds.Relations.Add(New DataRelation("ChildRelation",
ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ID")))

Everuthing is working fine, but when I try to add new row into table like
....

Dim r As DataRow

r = ds.Tables(1).NewRow()
r("ArticleNr") = "1234567890"
'...some other fields here too
ds.Tables(1).Rows.Add(r)

.... I'll get an error like ...

"Cannot set column 'ArticleNr' to '1234567890'. The value violates the
MaxLength limit of this column."

When I check this column using 'Command Window - Immediate' like...

?ds.Tables(1).Columns("ArticleNr").MaxLength
8

Why 8 ??! Anyway length is 40 in database table! I'm wondering is the
problem in ODBC driver or connection, or my code, or MySQL database
settings. This ds.Tables(1) is Child-table for ds.Tables(0) Master-table.
How can I ensure MaxLength limit to 40 for this field?

Propably Microsoft people don't mind to help me because MySQL is not their
products, but maybe someone else would kindly help me.
 
Hi Mika,

Sounds strange, you can set it, but than you have probably an error when you
does the updating of it, so that would not help.

Why not write the dataset to disk to check. You can do that with.

yourdataset.writeXML("Yourfilepath", XmlWriteMode.WriteSchema)

Then you see exactly see how it is configured.

Cor
 
Cor said:
Hi Mika,

Sounds strange, you can set it, but than you have probably an error when you
does the updating of it, so that would not help.

Why not write the dataset to disk to check. You can do that with.

yourdataset.writeXML("Yourfilepath", XmlWriteMode.WriteSchema)

Then you see exactly see how it is configured.

Cor

Thanks for your quick response Cor !

I just saved it into XML-file as you informed me and see the following lines
....

<xs:element name="ArticleNr">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>

.... but what I should to do to correct this? Anyway data is retrieved from
database server, not XML-file - so changing 8 to 40 in this XML file doesn't
affect anyway in my case ofcourse. Well - I'm quite out of this kind things
:(

-- Mika
 
Hi Mika,

Are you absolutly sure that the max length, (not the length ) is not set in
your database?

I can assure you that I know nothing from mySQL but I think that that option
should be somewhere set (or in the select).

Cor
 
Hi Mika,

I guess that mySql provider sets incorrect value.
You might generate dataset at design time and correct the values (or correct
them at runtime).
 
Back
Top