Convert String Data Type to UniqueIdentifier data type

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
 
W

William Ryan

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")
 
M

Miha Markic

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")
 
J

J Jones

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
 
M

Miha Markic

Hi,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top