Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBADO.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:
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
 
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 10-Jun-12 2:53am
Edited 10-Jun-12 5:46am
v2
Rate this: bad
good
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?
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
Patsail1 at 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 at 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
good
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.
  Permalink  
v2
Comments
Patsail1 at 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 at 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 OriginalGriff 183
2 Tadit Dash 160
3 Sergey Alexandrovich Kryukov 136
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,280
1 OriginalGriff 5,473
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid