Set sqlDataAdapter Parameter to null in a web method
Posted on 2004-11-17
I am writing a webmethod that uses a sqlDataAdapter to call a stored procedure within my SQL database. The function arguments are used to pass parameters to the stored procedure which then filter the selected rows. I have written the stored procedure so that it will ignore parameters that are null if the user does not want to filter on those fields. My problem is that I don't know how to pass a null value to the sqlDataAdapter parameters collection.
How would I change this code to change my integer arguments to NULL if they are passed with a value of say ZERO indicating that this field should not be filtered on?
<WebMethod()> Public Function GetTasks(ByVal strForeignTable As String, _
ByVal intForeignKey As Integer, ByVal intOwner As Integer, _
ByVal intSupervisor As Integer) As DataSetTasks
Dim Tasks As New DataSetTasks
.SelectCommand.Parameters("@ForeignTable").Value = strForeignTable
.SelectCommand.Parameters("@ForeignKey").Value = intForeignKey
.SelectCommand.Parameters("@Owner").Value = intOwner
.SelectCommand.Parameters("@Supervisor").Value = intSupervisor