Coen Posted July 30, 2004 Posted July 30, 2004 I'm trying to insert some records in a MySQL database with a DataSet but I'm getting an error when I try to set the value of a column. This is the code I'm using: Dim odbcDataSet As New DataSet Dim odbcDataAdapter As New OdbcDataAdapter(New OdbcCommand("SELECT * FROM MyTable", dbMySql)) odbcDataAdapter.InsertCommand = New OdbcCommand("INSERT INTO MyTable (MyColumn) VALUES (@MyColumn)", dbMySql) odbcDataAdapter.InsertCommand.Parameters.Add(New OdbcParameter("@MyColumn", OdbcType.VarChar, 30, "MyColumn")) odbcDataAdapter.FillSchema(odbcDataSet, SchemaType.Source) odbcDataSet.Tables(0).TableName = "MyTable" Dim odbcDataRow As DataRow = odbcDataSet.Tables("MyTable").NewRow() odbcDataRow("MyColumn") = "yhjhgj" odbcDataSet.Tables("MyTable").Rows.Add(odbcDataRow) odbcDataAdapter.Update(odbcDataSet, "MyTable") The MySql server is version 3.something and this is the error I'm getting: System.ArgumentException: Cannot set column 'MyColumn' to 'yhjhgj'. The value violates the MaxLength limit of this column. Why is this error occuring while I set the columns length to 30 (which is VARCHAR(30))? Quote
samsmithnz Posted July 30, 2004 Posted July 30, 2004 Are you sure that the actual database column and stored procedure variables are also varchar(30)?? Double check... Quote Thanks Sam http://www.samsmith.co.nz
*Experts* Nerseus Posted July 30, 2004 *Experts* Posted July 30, 2004 To add to sam's comment, you have the following line which will get you the maxlength of the column in the DB: odbcDataAdapter.FillSchema(odbcDataSet, SchemaType.Source) You should be able to check the DB's length with: Dim i As Integer = odbcDataSet.Tables(0).Columns("MyColumn").MaxLength -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Coen Posted August 2, 2004 Author Posted August 2, 2004 I've checked the column again samsmithnz but I'm sure it's VARCHAR(30) :p And when I get the column size it's MaxLength is 8? So ADO.NET doesn't seem te be able to get the correct column length... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.