473,770 Members | 4,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

myrow= datasetTarget.T ables(0).NewRow
'fill all columns here like..
row(i)= myvalue
' then
datasetTarget.T ables(0).Rows.A dd(myrow)
dataAdapterTarg et.Update(datas etTarget.Tables (0)) '*

I get "Invalid cast from system.byte to system.byte[]"
exception.messa ge 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 OledbDataAdapte r, 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 6328

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=VFPO LEDB;Data
Source=D:\dotne ttst")
Dim oCmd As New OleDbCommand()

oConn.Open()
oCmd.Connection = oConn
oCmd.CommandTyp e = CommandType.Tex t
oCmd.CommandTex t = "Insert Into TST Values (4000,[])"
oCmd.ExecuteNon Query()

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.c om>
*--Sender: <pe***@chsoft.c om>
*--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: AcNYV9tYzVT7zyX rRfCHya3yr3WHJQ ==
*--X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
*--Newsgroups: microsoft.publi c.dotnet.genera l
*--Path: cpmsftngxa06.ph x.gbl
*--Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:103149
*--NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
*--X-Tomcat-NG: microsoft.publi c.dotnet.genera l
*--
*--When I execute the following (with an OleDBDataAdapte r),
*--wanting to add a row to a visual foxpro table:
*--
*-- myrow= datasetTarget.T ables(0).NewRow
*-- 'fill all columns here like..
*-- row(i)= myvalue
*-- ' then
*-- datasetTarget.T ables(0).Rows.A dd(myrow)
*-- dataAdapterTarg et.Update(datas etTarget.Tables (0)) '*
*--
*-- I get "Invalid cast from system.byte to system.byte[]"
*--exception.messa ge 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 OledbDataAdapte r, 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
14506
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 program (UNIX) as an array of "struct point" where struct point //C structure { int Time; //32 bits
17
2677
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 cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
0
1567
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 as an object and the data looks fine. However when I do the type casting I get the above error. Any ideas. Below is the code. At the bottom you can see the comment on the cast that blows. I have even tried it without using the Object*. I just...
5
3437
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
2291
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 DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
7
2398
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 into imgPhoto Dim imgPhoto As System.Drawing.Image = System.Drawing.Image.FromStream(myStream) Dim dbConn, SQLStmt, dbComm, dbRead, img Dim myStream 'As New MemoryStream dbConn = New
1
4905
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 specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
1
312
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 ' then datasetTarget.Tables(0).Rows.Add(myrow) dataAdapterTarget.Update(datasetTarget.Tables(0)) '*
1
1699
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 System.Boolean to System.Byte. The code which defines the parameter and assigns the value of the check box to the parameter in the application is: Dim prmBackedUp As New SqlParameter("@BackedUp", SqlDbType.Binary)
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.