Invalid cast from system.byte to system.byte[]

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I execute the following (with an OleDBDataAdapter),
wanting to add a row to a visual foxpro table:

myrow= datasetTarget.Tables(0).NewRow
'fill all columns here like..
row(i)= myvalue
' then
datasetTarget.Tables(0).Rows.Add(myrow)
dataAdapterTarget.Update(datasetTarget.Tables(0)) '*

I get "Invalid cast from system.byte to system.byte[]"
exception.message executing the * marked line, when I use
row(i)=cbyte(1).
I get the message "ColumnName does not accept null values"
when I use row(i)=b ', where dim b as system.byte =
{12,13,14}
Assigning other data types like integer, double, even with
cbyte(..) gives similar errors.

The failing column is from a Visual Foxpro table (to which
I connected via an OledbDataAdapter, using vfpoledb.dll
ver 8.0.0.2521).
The trouble column is not nullable. Its VFP data type is
'General', as shown by the VFP ver 6 IDE Table Designer.
I cannot change the type of the column (it's not my table).
So what do I assign to row(i) in this case if I want to
leave it empty

(in case of a string type I would assign row(i)="").
This column is supposed to store bit images from icons, but
I need to fill this column with nothing, not having any
icon bitmaps.
This problem appears only when the VFP datatype is
'General'; otherwise my column filling algorithm works.
TIA
 
Hello Peter,

My name is Trevor Hancock. I am a member of the Visual FoxPro support team
and I will try to help here.

Fox itself has no method to store an empty value to a GENERAL field. There
are only two ways to populate that type of field in Fox:

(1) The APPEND GENERAL command.
(2) Using the VFP IDE, specifically the Edit>Insert Object menu option.

There is no way to insert a value into the general field with an UPDATE or
INSERT command. For instance, let's say we have a table named TST with two
fields:

IID Int
MYGEN General

This command will produce a data type mismatch error inside VFP:

INSERT INTO TST VALUES (1,"")

As I said, past the IDE and the APPEND GENERAL command, there is no way to
populate that GENERAL field.


However, I have found something interesting with the VFP OLE DB Provider
and .NET. The following code allows me to insert a new record into the
aforementioned table:

Dim oConn As New OleDbConnection("Provider=VFPOLEDB;Data
Source=D:\dotnettst")
Dim oCmd As New OleDbCommand()

oConn.Open()
oCmd.Connection = oConn
oCmd.CommandType = CommandType.Text
oCmd.CommandText = "Insert Into TST Values (4000,[])"
oCmd.ExecuteNonQuery()

oConn.Close()
oConn.Dispose()
oCmd.Dispose()

What is odd to me about this is the fact that this very same INSERT
command, when run inside VFP will error out. However, through the provider
it works fine!

I am in discussions with my product group over this, but in the meantime
this may help you get around your problem.

Respectfully,
Trevor Hancock, MCSD
Microsoft Developer Support - FoxPro

*-- VFP8 HAS ARRIVED!! --*
Read about all the new features of VFP8 here:
http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
Purchase VFP8 here:
http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
- VFP5 Mainstream Support retires June 30th, 2003
- VFP6 Mainstream Support retires Sep. 30th, 2003

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
*--Content-Class: urn:content-classes:message
*--From: <[email protected]>
*--Sender: <[email protected]>
*--Subject: Invalid cast from system.byte to system.byte[]
*--Date: Fri, 1 Aug 2003 11:08:06 -0700
*--Lines: 36
*--Message-ID: <[email protected]>
*--MIME-Version: 1.0
*--Content-Type: text/plain;
*-- charset="iso-8859-1"
*--Content-Transfer-Encoding: 7bit
*--X-Newsreader: Microsoft CDO for Windows 2000
*--Thread-Index: AcNYV9tYzVT7zyXrRfCHya3yr3WHJQ==
*--X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
*--Newsgroups: microsoft.public.dotnet.general
*--Path: cpmsftngxa06.phx.gbl
*--Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103149
*--NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
*--X-Tomcat-NG: microsoft.public.dotnet.general
*--
*--When I execute the following (with an OleDBDataAdapter),
*--wanting to add a row to a visual foxpro table:
*--
*-- myrow= datasetTarget.Tables(0).NewRow
*-- 'fill all columns here like..
*-- row(i)= myvalue
*-- ' then
*-- datasetTarget.Tables(0).Rows.Add(myrow)
*-- dataAdapterTarget.Update(datasetTarget.Tables(0)) '*
*--
*-- I get "Invalid cast from system.byte to system.byte[]"
*--exception.message executing the * marked line, when I use
*--row(i)=cbyte(1).
*-- I get the message "ColumnName does not accept null values"
*--when I use row(i)=b ', where dim b as system.byte =
*--{12,13,14}
*-- Assigning other data types like integer, double, even with
*--cbyte(..) gives similar errors.
*--
*-- The failing column is from a Visual Foxpro table (to which
*-- I connected via an OledbDataAdapter, using vfpoledb.dll
*--ver 8.0.0.2521).
*--The trouble column is not nullable. Its VFP data type is
*--'General', as shown by the VFP ver 6 IDE Table Designer.
*--I cannot change the type of the column (it's not my table).
*--So what do I assign to row(i) in this case if I want to
*--leave it empty
*--
*--(in case of a string type I would assign row(i)="").
*--This column is supposed to store bit images from icons, but
*-- I need to fill this column with nothing, not having any
*--icon bitmaps.
*--This problem appears only when the VFP datatype is
*--'General'; otherwise my column filling algorithm works.
*--TIA
*--
*--
 
Back
Top