|
-
Oct 26th, 2007, 10:55 PM
#1
Thread Starter
Hyperactive Member
(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:
'
Private Sub SelectRecordstoDelete()
Dim cnn As New SqlConnection(aCon)
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet
cmd = cnn.CreateCommand
cmd.CommandText = "Select FormID From " & _
"tbl_Forms Where DateSubmitted Between " & _
"'2007-02-02' and '2007-02-06'"
da.SelectCommand = cmd
da.Fill(ds, "IDs")
With ds.Tables("IDs")
For i As Integer = 0 To .Rows.Count - 1
DeleteRecords(.Rows(i).Item(0))
Next
End With
End Sub
Sub DeleteRecords(ByVal myGUID As Guid)
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim strSp As String = "spd_DeleteForm"
Dim cn As SqlConnection = New SqlConnection(aCon)
Dim cmd As SqlCommand = New SqlCommand(strSp, cn)
cn.Open()
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add( _
"@FormID", _
SqlDbType.VarChar, 50).Direction = _
ParameterDirection.Input
.Parameters("@FormID").Value = myGUID
.ExecuteNonQuery()
End With
End Sub
Last edited by FastEddie; Oct 26th, 2007 at 11:04 PM.
-
Oct 26th, 2007, 11:02 PM
#2
Thread Starter
Hyperactive Member
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:
'
With ds.Tables("IDs")
For i As Integer = 0 To .Rows.Count - 1
DeleteRecords(.Rows(i).Item(0).ToString)
Next
End With
End Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|