L
Larry
I get a "Specified cast is not valid" when excuting the following line in
the subroutine below:
spParm = spAddImage.Parameters("@fnameIn").Value =
ckfile.Text
I'm not sure what I'm doing wrong to cause this error. I'm using the
following to set up this parameter:
spParm = spAddImage.Parameters.Add("@fnameIn",
SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Input
any ideas?
-Larry
Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)HandlesbtnTransfer.Click
Dim srcpath, destpath As String
Dim ckfile As ListViewItem
' set up to execute the stored procedure
Dim spAddImage As New SqlClient.SqlCommand("spAddImage",
Me.SqlConnection1)
spAddImage.CommandType = CommandType.StoredProcedure
Dim spParm As SqlClient.SqlParameter
spParm = spAddImage.Parameters.Add("@fnameIn", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Input
spParm = spAddImage.Parameters.Add("@fstatus", 2)
spParm = spAddImage.Parameters.Add("@srcDir", curntSrcDir)
spParm = spAddImage.Parameters.Add("@fnameOut", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Output
spParm = spAddImage.Parameters.Add("@spError", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Output
For Each ckfile In Me.lvSrcFileList.Items
If ckfile.Checked Then
srcpath = curntSrcDir & "\" & ckfile.Text
Try
If System.IO.File.Exists(srcpath) Then
' enter file into database and get the new file designation in return
spParm = spAddImage.Parameters("@fnameIn").Value =
ckfile.Text
Me.SqlConnection1.Open()
spAddImage.ExecuteNonQuery()
Me.SqlConnection1.Close()
If IsDBNull(spAddImage.Parameters("@spError").Value)
Then
errormsg(spAddImage.Parameters("@spError").Value)
Else
' now copy and rename the file
destpath = Me.txtDestination.Text & "\" &
spAddImage.Parameters("@fnameOut").Value
System.IO.File.Copy(srcpath, destpath)
ckfile.Checked = False
End If
End If
Catch ex As Exception
errormsg(ex.Message)
End Try
End If
Next
End Sub
the subroutine below:
spParm = spAddImage.Parameters("@fnameIn").Value =
ckfile.Text
I'm not sure what I'm doing wrong to cause this error. I'm using the
following to set up this parameter:
spParm = spAddImage.Parameters.Add("@fnameIn",
SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Input
any ideas?
-Larry
Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)HandlesbtnTransfer.Click
Dim srcpath, destpath As String
Dim ckfile As ListViewItem
' set up to execute the stored procedure
Dim spAddImage As New SqlClient.SqlCommand("spAddImage",
Me.SqlConnection1)
spAddImage.CommandType = CommandType.StoredProcedure
Dim spParm As SqlClient.SqlParameter
spParm = spAddImage.Parameters.Add("@fnameIn", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Input
spParm = spAddImage.Parameters.Add("@fstatus", 2)
spParm = spAddImage.Parameters.Add("@srcDir", curntSrcDir)
spParm = spAddImage.Parameters.Add("@fnameOut", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Output
spParm = spAddImage.Parameters.Add("@spError", SqlDbType.VarChar, 256)
spParm.Direction = ParameterDirection.Output
For Each ckfile In Me.lvSrcFileList.Items
If ckfile.Checked Then
srcpath = curntSrcDir & "\" & ckfile.Text
Try
If System.IO.File.Exists(srcpath) Then
' enter file into database and get the new file designation in return
spParm = spAddImage.Parameters("@fnameIn").Value =
ckfile.Text
Me.SqlConnection1.Open()
spAddImage.ExecuteNonQuery()
Me.SqlConnection1.Close()
If IsDBNull(spAddImage.Parameters("@spError").Value)
Then
errormsg(spAddImage.Parameters("@spError").Value)
Else
' now copy and rename the file
destpath = Me.txtDestination.Text & "\" &
spAddImage.Parameters("@fnameOut").Value
System.IO.File.Copy(srcpath, destpath)
ckfile.Checked = False
End If
End If
Catch ex As Exception
errormsg(ex.Message)
End Try
End If
Next
End Sub