Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
ConRatingDB.Open()
Me.PersonsTableAdapter.Fill(Me.DsRatingDbSQL.Persons)
daPersons.Fill(DsRatingDbSQL, "Persons")
ConRatingDB.Close()

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

VB
daPersons.Update(DsRatingDbSQL.Tables("Persons"))
DsRatingDbSQL.Tables("Persons").Clear()
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())
Or:
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
Updated 10-Jun-12 5:46am
v2

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.
 
Share this answer
 
v2
Comments
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.
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.
 
Share this answer
 
Comments
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:
daPersons.Update(DsRatingDbSQL.Tables("Persons"))

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.
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?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900