473,417 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

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

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

Jul 19 '05 #1
1 6294

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/Visua...FP8Release.asp
Purchase VFP8 here:
http://shop.microsoft.com/Referral/P...p?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: <pe***@chsoft.com>
*--Sender: <pe***@chsoft.com>
*--Subject: Invalid cast from system.byte to system.byte[]
*--Date: Fri, 1 Aug 2003 11:08:06 -0700
*--Lines: 36
*--Message-ID: <02****************************@phx.gbl>
*--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
*--
*--

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
0
by: BobTheHacker | last post by:
I have a c# class library that I call to centralize some code amongst projects. It returns an arraylist back to the calling function that contains class data. Anyway when I call it I can receive it...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
7
by: Robson Carvalho Machado | last post by:
Does anyone knows how to CAST this SQL Response into a MemoryStream ?? When executing below code an error message says "Specified cast is not valid" I need to put this into MemoryStream to use it...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
1
by: | last post by:
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 '...
1
by: JackO | last post by:
I have a check box on a Web form that I have named “chkBackedUp”. When I run the application, I receive the following error: Exception Details: System.InvalidCastException: Invalid cast from...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.