Convert String Data Type to UniqueIdentifier data type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I am facing this problem " specified cast is not valid" when I assgin a string data type into SqlDataAdapter's sql parameter
I would like to know how to convert string data type variable to UniqueIdentifier data type? Thank yo
Dim paraAppID As SqlParamete
paraAppID = cmd.Parameters.Add("@AppID", SqlDbType.UniqueIdentifier, 16, "AppID")
paraAppID.Direction = ParameterDirection.Inpu
paraAppID.Value = strAppID

Regard
ang
 
If I understand you correctly, why not just let the DB take care of this
for you?
ang said:
Hi,
I am facing this problem " specified cast is not valid" when I assgin a
string data type into SqlDataAdapter's sql parameter.
I would like to know how to convert string data type variable to
UniqueIdentifier data type? Thank you
Dim paraAppID As SqlParameter
paraAppID = cmd.Parameters.Add("@AppID",
SqlDbType.UniqueIdentifier, 16, "AppID")
 
Hi,

You should use Guid data type instead of string.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

ang said:
Hi,
I am facing this problem " specified cast is not valid" when I assgin a
string data type into SqlDataAdapter's sql parameter.
I would like to know how to convert string data type variable to
UniqueIdentifier data type? Thank you
Dim paraAppID As SqlParameter
paraAppID = cmd.Parameters.Add("@AppID",
SqlDbType.UniqueIdentifier, 16, "AppID")
 
Private Function StringToGuid(ByVal sValue As String) As System.Guid

Dim guidValue As System.Guid = _
CType(System.ComponentModel.TypeDescriptor.GetConverter( _
guidValue).ConvertFrom(sValue), System.Guid)
Return guidValue

End Function
 
Hi,

Dim g as new Guid(value) should be even easier :)
However, i suspect the original poster should not use strings at all...
 
Back
Top