clearchannel
asked on
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
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
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
SP
--
CREATE PROCEDURE AddPicture
@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)
AS
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
GO
INSERTPICTURES
--------------
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)
doGlobal.mySQLCmd.Parameters.Add(param1)
Dim param2 As New SqlClient.SqlParameter("@WorkOrderNo", SqlDbType.Int)
param2.Direction = ParameterDirection.Input
param2.Value = Trim(WorkOrderNo)
doGlobal.mySQLCmd.Parameters.Add(WorkOrderNo)
Dim param3 As New SqlClient.SqlParameter("@IssueNo", SqlDbType.Int)
param3.Direction = ParameterDirection.Input
param3.Value = Trim(IssueNo)
doGlobal.mySQLCmd.Parameters.Add(param3)
Dim param4 As New SqlClient.SqlParameter("@RoundName", SqlDbType.NVarChar, 75)
param4.Direction = ParameterDirection.Input
param4.Value = Trim(RoundName)
doGlobal.mySQLCmd.Parameters.Add(param4)
Dim param5 As New SqlClient.SqlParameter("@OperativeNo", SqlDbType.Int)
param5.Direction = ParameterDirection.Input
param5.Value = Trim(OperativeNo)
doGlobal.mySQLCmd.Parameters.Add(param5)
Dim param6 As New SqlClient.SqlParameter("@InChargeDate", SqlDbType.Date)
param6.Direction = ParameterDirection.Input
param6.Value = Trim(InChargeDate)
doGlobal.mySQLCmd.Parameters.Add(param6)
Dim param7 As New SqlClient.SqlParameter("@LocationNo", SqlDbType.Int)
param7.Direction = ParameterDirection.Input
param7.Value = Trim(LocationNo)
doGlobal.mySQLCmd.Parameters.Add(param7)
Dim param8 As New SqlClient.SqlParameter("@PanelNo", SqlDbType.Int)
param8.Direction = ParameterDirection.Input
param8.Value = Trim(PanelNo)
doGlobal.mySQLCmd.Parameters.Add(param8)
Dim param9 As New SqlClient.SqlParameter("@WorkDate", SqlDbType.SmallDateTime)
param9.Direction = ParameterDirection.Input
param9.Value = Trim(WorkDate)
doGlobal.mySQLCmd.Parameters.Add(param9)
Dim param10 As New SqlClient.SqlParameter("@WorkTime", SqlDbType.SmallDateTime)
param10.Direction = ParameterDirection.Input
param10.Value = Trim(WorkTime)
doGlobal.mySQLCmd.Parameters.Add(param10)
Dim param11 As New SqlClient.SqlParameter("@DesignName", SqlDbType.NVarChar, 4000)
param11.Direction = ParameterDirection.Input
param11.Value = Trim(DesignName)
doGlobal.mySQLCmd.Parameters.Add(param11)
Dim param12 As New SqlClient.SqlParameter("@GPSLatitude", SqlDbType.NVarChar, 50)
param12.Direction = ParameterDirection.Input
param12.Value = Trim(GPSLatitude)
doGlobal.mySQLCmd.Parameters.Add(param12)
Dim param13 As New SqlClient.SqlParameter("@GPSLongitude", SqlDbType.NVarChar, 50)
param13.Direction = ParameterDirection.Input
param13.Value = Trim(GPSLongitude)
doGlobal.mySQLCmd.Parameters.Add(param13)
Dim param14 As New SqlClient.SqlParameter("@MOMSFeedback", SqlDbType.NVarChar, 4000)
param14.Direction = ParameterDirection.Input
param14.Value = Trim(Feedback)
doGlobal.mySQLCmd.Parameters.Add(param14)
Try
doGlobal.mySQLConn.Open()
doGlobal.mySQLCmd.ExecuteNonQuery()
doGlobal.mySQLConn.Close()
Catch ex As Exception
doGlobal.mySQLConn.Close()
doGlobal.doError("Database.vb/insertPicture: " & ex.Message.ToString, ApplicationLog)
End Try
End Sub
picturesXML.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is your problem that the GPSLatitude contains ' characters in the 2nd Picture block cant remember if this causes as issue with XML
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
JINN
We will see if you need further assistance
JINN
ASKER
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???
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???
JINN
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???
JINN
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://msdn.microsoft.com/en-us/library/ms186724.aspx
http://msdn.microsoft.com/en-us/library/ms186724.aspx