Results 1 to 2 of 2

Thread: (Resolved) Convert Guid to String Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    (Resolved) Convert Guid to String Error

    I am trying to pass a series GUIDs to a Stored Procedure and am getting this error:

    Failed to convert parameter value from a Guid to a String (focus goes to the ExecuteNonQuery.

    VB Code:
    1. '
    2.     Private Sub SelectRecordstoDelete()
    3.         Dim cnn As New SqlConnection(aCon)
    4.         Dim cmd As New SqlCommand
    5.         Dim da As New SqlDataAdapter
    6.         Dim ds As New DataSet
    7.         cmd = cnn.CreateCommand
    8.         cmd.CommandText = "Select FormID From " & _
    9.         "tbl_Forms Where DateSubmitted Between " & _
    10.         "'2007-02-02' and '2007-02-06'"
    11.         da.SelectCommand = cmd
    12.         da.Fill(ds, "IDs")
    13.         With ds.Tables("IDs")
    14.             For i As Integer = 0 To .Rows.Count - 1
    15.                 DeleteRecords(.Rows(i).Item(0))
    16.             Next
    17.         End With
    18.     End Sub
    19.  
    20.     Sub DeleteRecords(ByVal myGUID As Guid)
    21.         Dim da As New SqlDataAdapter
    22.         Dim ds As New DataSet
    23.         Dim strSp As String = "spd_DeleteForm"
    24.         Dim cn As SqlConnection = New SqlConnection(aCon)
    25.         Dim cmd As SqlCommand = New SqlCommand(strSp, cn)
    26.         cn.Open()
    27.         With cmd
    28.             .CommandType = CommandType.StoredProcedure
    29.             .Parameters.Add( _
    30.                 "@FormID", _
    31.                 SqlDbType.VarChar, 50).Direction = _
    32.                 ParameterDirection.Input
    33.             .Parameters("@FormID").Value = myGUID
    34.             .ExecuteNonQuery()
    35.         End With
    36.     End Sub
    Last edited by FastEddie; Oct 26th, 2007 at 11:04 PM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Convert Guid to String Error

    I figured it out right after I posted. I just needed the ToString, which I didn't try before because I was originaly trying to cast it to a string and it just failed.
    VB Code:
    1. '
    2.         With ds.Tables("IDs")
    3.             For i As Integer = 0 To .Rows.Count - 1
    4.                 DeleteRecords(.Rows(i).Item(0).ToString)
    5.             Next
    6.         End With
    7.     End Sub
    8.  
    9.     Sub DeleteRecords(ByVal myGUID As String)
    Last edited by FastEddie; Oct 26th, 2007 at 11:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width