Click here to Skip to main content
11,928,569 members (50,661 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB ADO.NET
My SQL database (RatingDbSQL) has 3 tables and the 'Persons' table comprises:
Column(0) as Unique ID;
Column(1) FirstName as String; Column(2) LastName as String.

The database Provider is: .NET Framework Data Provider for SQL Server

The data loads from the Database OK using:
daPersons.Fill(DsRatingDbSQL, "Persons")
The other two tables are non starters until I resolve saving data to the Persons Table using the following:
- - - - - - - - - - -

The first line (Update) returns with:
System.InvalidCastException – Failed to convert parameter value from a Int32 to a Guid

daPersons.Fill(DsRatingDbSQL, "Persons")
The Properties of the ID column are:
DataType: UniqueIdentifier
Length: 16
Nullable: False

- - - - - - - - - - -
I have read many Internet articles on similar problems but don’t understand how to implement them:

The following three look interesting – but I’m lost on how to implement:
Guid guid = new Guid(sqlCmd.Parameters["@UserID"].Value.ToString())
Dim ID as String = commandArgs(0).ToString()
Dim FirstName as String = commandArgs(1).ToString()
Dim LastName as String = commandArgs(2).ToString()
Or:Dim i as Integer
Public Overridable Function GetGuid(ByVal i As Integer) As Guid Implements IDataRecord.GetGuid

Could anyone advise please
Posted 10-Jun-12 3:53am
Edited 10-Jun-12 6:46am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You cannot use casts to convert from one value type to another. Why are you trying to get a GUID when your values are integer, string and (I guess) boolean?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You cannot really convert a GUID type to an integer.
If you try and convert, GUID to an int, you will lose a part of the GUID information at least.

GUID's are identifiers in themselves so you should be able to use them directly.
Patsail1 11-Jun-12 3:26am
Richard, Abhinav

Thanks for responding and sorry if my problem was not clear

When de-bugging

The program stops at the line:

and Outputs the following error:
InvalidCastException was unhandled
System.InvalidCastException – Failed to convert parameter value from a Int32 to a Guid

I don't want a Guid - the error system asks for it

I only want to use integer, string and (later) boolean?

Pat 'D
Richard MacCutchan 11-Jun-12 4:39am
Please edit your question to show what all these methods are doing. Somewhere in there you are calling a method with an Int32 as a parameter, where a GUID is expected. However with the information you have provided it is impossible to guess where or why.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Having looked at the MSDN documentation[^], I see that UniqueIdentifier elements are GUID values. I can only assume that you have replaced one with an integer, or have an integer item in your table, which causes Update() to throw this error.
Patsail1 11-Jun-12 5:25am
Desperation set in:
I have re-constructed the Form and copied the identical coding to the new form.
Old Form then deleted
I no longer get an error - Obviously the file was corrupted, location unknown
Sorry to have posted, I could have done this sooner

Pat 'D
Richard MacCutchan 11-Jun-12 5:28am
No problem, this sort of thing happens to us all from time to time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100