Problem with sqlparamater in stored procedure

I have an issue with a SQLParameter in some code I am suing but I can't find the problem.
What I am doing is reading in an xml file, inserting the info into a db table and then moving the images that are referenced in the xml file to enw locations. The error that is being reported is:

import.aspx/InsertPictures: The SqlParameterCollection only accepts non-null SqlParameter type objects, not Int32 objects.

I have attached a copy of the XML and code below. I would be grateful if someone could point out the issue for me and explain where I have gone wrong. Thanks

@PictureName nvarchar(150), @WorkOrderNo int, @IssueNo int, @RoundName nvarchar(75), @OperativeNo int, @InChargeDate smalldatetime, @LocationNo int, @PanelNo int, @WorkDate smalldatetime, @WorkTime smalldatetime, @DesignName nvarchar(4000), @GPSLatitude nvarchar(50), @GPSLongitude nvarchar(50), @MOMSFeedback nvarchar(4000), @Country nvarchar(50)
declare @sql nvarchar(2500)
set @sql = 'INSERT INTO [' + @Country + '] (PictureName, WorkOrderNo, IssueNo, RoundName, OperativeNo, InChargeDate, LocationNo, PanelNo, WorkDate, WorkTime, DesignName, GPSLatitiude, GPSLongitude, MOMSFeedback)
VALUES (@PictureName, @WorkOrderNo, @IssueNo, @RoundName, @OperativeNo, @InChargeDate, @LocationNo, @PanelNo, @WorkDate, @WorkTime, @DesignName, @GPSLatitude, @GPSLongitude, @MOMSFeedback) ' 
exec sp_executesql @sql, N'@PictureName nvarchar(150), @WorkOrderNo int, @IssueNo int, @RoundName nvarchar(75), @OperativeNo int, @InChargeDate smalldatetime, @LocationNo int, @PanelNo int, @WorkDate smalldatetime, @WorkTime smalldatetime, @DesignName nvarchar(4000), @GPSLatitude nvarchar(50), @GPSLongitude nvarchar(50), @MOMSFeedback nvarchar(4000)', @PictureName, @WorkOrderNo, @IssueNo, @RoundName, @OperativeNo, @InChargeDate, @LocationNo, @PanelNo, @WorkDate, @WorkTime, @DesignName, @GPSLatitude, @GPSLongitude, @MOMSFeedback
Public Sub insertPictures(ByVal PictureName As String, ByVal WorkOrderNo As Integer, ByVal IssueNo As Integer, ByVal RoundName As String, ByVal OperativeNo As Integer, ByVal InChargeDate As String, ByVal LocationNo As Integer, ByVal PanelNo As Integer, ByVal WorkDate As String, ByVal WorkTime As String, ByVal DesignName As String, ByVal GPSLatitude As String, ByVal GPSLongitude As String, ByVal Feedback As String, ByVal ApplicationLog As String)
        doGlobal.mySQLCmd = New SqlClient.SqlCommand("AddPicture", doGlobal.mySQLConn)
        doGlobal.mySQLCmd.CommandType = CommandType.StoredProcedure
        Dim param1 As New SqlClient.SqlParameter("@PictureName", SqlDbType.NVarChar, 150)
        param1.Direction = ParameterDirection.Input
        param1.Value = Trim(PictureName)
        Dim param2 As New SqlClient.SqlParameter("@WorkOrderNo", SqlDbType.Int)
        param2.Direction = ParameterDirection.Input
        param2.Value = Trim(WorkOrderNo)
        Dim param3 As New SqlClient.SqlParameter("@IssueNo", SqlDbType.Int)
        param3.Direction = ParameterDirection.Input
        param3.Value = Trim(IssueNo)
        Dim param4 As New SqlClient.SqlParameter("@RoundName", SqlDbType.NVarChar, 75)
        param4.Direction = ParameterDirection.Input
        param4.Value = Trim(RoundName)
        Dim param5 As New SqlClient.SqlParameter("@OperativeNo", SqlDbType.Int)
        param5.Direction = ParameterDirection.Input
        param5.Value = Trim(OperativeNo)
        Dim param6 As New SqlClient.SqlParameter("@InChargeDate", SqlDbType.Date)
        param6.Direction = ParameterDirection.Input
        param6.Value = Trim(InChargeDate)
        Dim param7 As New SqlClient.SqlParameter("@LocationNo", SqlDbType.Int)
        param7.Direction = ParameterDirection.Input
        param7.Value = Trim(LocationNo)
        Dim param8 As New SqlClient.SqlParameter("@PanelNo", SqlDbType.Int)
        param8.Direction = ParameterDirection.Input
        param8.Value = Trim(PanelNo)
        Dim param9 As New SqlClient.SqlParameter("@WorkDate", SqlDbType.SmallDateTime)
        param9.Direction = ParameterDirection.Input
        param9.Value = Trim(WorkDate)
        Dim param10 As New SqlClient.SqlParameter("@WorkTime", SqlDbType.SmallDateTime)
        param10.Direction = ParameterDirection.Input
        param10.Value = Trim(WorkTime)
        Dim param11 As New SqlClient.SqlParameter("@DesignName", SqlDbType.NVarChar, 4000)
        param11.Direction = ParameterDirection.Input
        param11.Value = Trim(DesignName)
        Dim param12 As New SqlClient.SqlParameter("@GPSLatitude", SqlDbType.NVarChar, 50)
        param12.Direction = ParameterDirection.Input
        param12.Value = Trim(GPSLatitude)
        Dim param13 As New SqlClient.SqlParameter("@GPSLongitude", SqlDbType.NVarChar, 50)
        param13.Direction = ParameterDirection.Input
        param13.Value = Trim(GPSLongitude)
        Dim param14 As New SqlClient.SqlParameter("@MOMSFeedback", SqlDbType.NVarChar, 4000)
        param14.Direction = ParameterDirection.Input
        param14.Value = Trim(Feedback)
        Catch ex As Exception
            doGlobal.doError("Database.vb/insertPicture: " & ex.Message.ToString, ApplicationLog)
        End Try
    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hello clearchannel,

 23:          doGlobal.mySQLCmd.Parameters.Add(WorkOrderNo)

Should be

 23:          doGlobal.mySQLCmd.Parameters.Add(Param2)



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Is your problem that the GPSLatitude contains ' characters in the 2nd Picture block cant remember if this causes as issue with XML

Those parameters which has type Int, for example:

 Dim param2 As New SqlClient.SqlParameter("@WorkOrderNo", SqlDbType.Int)
        param2.Direction = ParameterDirection.Input
        param2.Value = Trim(WorkOrderNo) '<---- dont use Trim here
        doGlobal.mySQLCmd.Parameters.Add(param2 )

// just like this:
        Dim param3 As New SqlClient.SqlParameter("@IssueNo", SqlDbType.Int)
        param3.Direction = ParameterDirection.Input
        param3.Value = IssueNo

Well I am not sure if this is an issue but you can give it a try.


Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

clearchannelAuthor Commented:
Totally overlooked that! I had them set as nvarchars originally and forgot to take off the formatting!!!
I'll give it a go and see what difference it makes.
Also make sure you take care of the param2 as Timmy mentioned.

We will see if you need further assistance

clearchannelAuthor Commented:
Seems it was a culmination of things, although there's still an issue with the field WorkTime...

WorkTime sis et as smalldatetime and the time is coming to me in the format 10:36:02
When it is sinserted into the db it adds todays date at the begiining. How do I stop the SQL db form doing that and leaving just the time???
How is this field define in your database? So basically you just want the time in that field ?
Is this generic or sometimes this field can contains date?, cause I dont see the point of storing time only. Do you always want to store hours min sec only???

SQL contains only 2 type DateTime and SmallDateTime both of them will have date, there is no way you can eliminate the date part.

What we do in our case is we set our field as nvarchar and store the time like: hhmmss so it will be: 211534 (which is 21:15 34sec) we use this number to sort and display the way we want it (in another word: we dont use DateTime type data for this kind of scenarios)

Another solution is keep the SmallDateTime in the database field, let SQL add the date, we ignore the date when we display something.

Hope this helps
hi, check for the time column in database, is it datatime data type or is it string, try to make it to time (Transact-SQL) data type
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.