adding in web service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi..can anyone pls help me with the my code.when I execute this code and key in values such as 3 for jobNum and description for jobName, it can be added into the database but when I enter the values such as NP9008 for jobNum and description for jobName, it couldn’t be added into the database..i’m not sure why the jobNum field could only accept integer values when I’ve already set the parameters to varchar.thanks


<WebMethod()> _
Public Function addJob(ByVal jobNum As String, _
ByVal jobName As String) As DataSet

Dim addCommand As SqlCommand
addCommand = New SqlCommand _
("INSERT INTO Jobs" & _
"(JobNumber,JobName)" & _
"VALUES (" & jobNum & ", '" & _
jobName & "')")
ExecuteCommand(addCommand)
addCommand.Parameters.Add("@JobNumber", SqlDbType.VarChar, 15, "JobNumber")
addCommand.Parameters("@JobNumber").Value = jobNum
addCommand.Parameters.Add("@JobName", SqlDbType.VarChar, 50, "JobName")
addCommand.Parameters("@JobName").Value = jobName
Dim ds As DataSet = New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter(addCommand)
da.Fill(ds, "Jobs")
Return ds

End Function
 
This:
("INSERT INTO Jobs" & _
"(JobNumber,JobName)" & _
"VALUES (" & jobNum & ", '" & _
jobName & "')")

should be

("INSERT INTO Jobs" & _
"(JobNumber,JobName) " & _
"VALUES (@JobNumber, @JobName)")


--
Alex Feinman
---
Visit http://www.opennetcf.org
chris said:
Hi..can anyone pls help me with the my code.when I execute this code and
key in values such as 3 for jobNum and description for jobName, it can be
added into the database but when I enter the values such as NP9008 for
jobNum and description for jobName, it couldn't be added into the
database..i'm not sure why the jobNum field could only accept integer values
when I've already set the parameters to varchar.thanks
 
the information does not get into the database..it does not give an error msg..just that when i press the invoke button,it does not display any XML web service.
 
heloo...i've tried out a new way by using addCommand.CommandText then followed by my sql statement and it works fine..by the way,thanks you for your time
 
Back
Top