I'm trying to insert into the database an sql statement as in one of the variables hold an sql statement. This statement however has parameters and it shows up in the database as @parm instead of the actual values. Any ideas?
This is the statement:
Dim cmd As New SqlCommand("insert into MyTableOne (ID, QueryText) values (3,'insert into MyTableTwo (Name,Image,ClientId,Taskcode,TaskYear,Notes,ImgDT,Flag) values (@name,@img,@clientid,@taskcode,@taskyear,@notes,@imgdt,@flag)')", con)
this is how im filling in the values cmd.Parameters.AddWithValue("@name",Name) and Name is a value given as a parm in the method (this is all in a web service method then called from an app that provides the values)
New:
Dim cmd As New SqlCommand("insert into FTWebUploadQueue2_GVT (ID, QueryText) values (4,'insert into IMAGES_GVT (Name,Image,ClientId,Taskcode,TaskYear,Notes,ImgDT,Flag) values ('+ @name + ',' + @img + ',' + @clientid + ',' + @taskcode + ',' + @taskyear + ',' + @notes + ',' + @imgdt + ',' + @flag +')')", con)
<WebMethod()> _
Public Function SaveImageInBackoffice(ByVal imageData As Byte(), ByVal Name As String, ByVal ClientId As String, ByVal Taskcode As Integer, ByVal TaskYear As Integer, ByVal Notes As String, ByVal ImgDT As DateTime, ByVal Flag As Integer) As Boolean
Dim con As New SqlConnection("Server=****;uid=**;pwd=****;database=ImagesTrial")
If con.State = ConnectionState.Closed Then con.Open()
Dim cmd As New SqlCommand("insert into FTWebUploadQueue3_GVT (ID, QueryText) values (4,'insert into IMAGES_GVT (Name,Image,ClientId,Taskcode,TaskYear,Notes,ImgDT,Flag) values ('+ CAST(@name AS VARCHAR) + ',' + CAST(@img AS VARCHAR) + ',' + CAST(@clientid AS VARCHAR) + ',' + CAST(@taskcode AS VARCHAR) + ',' + CAST(@taskyear AS VARCHAR) + ',' + CAST(@notes AS VARCHAR) + ',' + CAST(@imgdt AS VARCHAR) + ',' + CAST(@flag AS VARCHAR) +')')", con)
cmd.Parameters.AddWithValue("@img", imageData)
cmd.Parameters.AddWithValue("@name", Name)
cmd.Parameters.AddWithValue("@clientid", ClientId)
cmd.Parameters.AddWithValue("@taskcode", Taskcode)
cmd.Parameters.AddWithValue("@taskyear", TaskYear)
cmd.Parameters.AddWithValue("@notes", Notes)
cmd.Parameters.AddWithValue("@imgdt", ImgDT)
cmd.Parameters.AddWithValue("@flag", Flag)
cmd.ExecuteNonQuery()
con.Close()
Return 0
End Function