Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to deal with "Nothing" 2

Status
Not open for further replies.

selinis

Programmer
Oct 15, 2001
29
CA
Hi all!

I get some strings into variables like:

Dim value as string=request.params("some_value")

I use these strings as Input parameters for a stored procedure wich is doing data insertion into a MS SQL server table.

Here is the problem: I get some variables whose values are "Nothing" (as debugger windows showed me..). After running the project there is an error:

"System.Data.SqlClient.SqlException: Procedure 'InsertValues' expects parameter '@my_param, which was not supplied."

What I can do in this case?
Thanks!

 
It may be a good idea to simply send the value to a function which could format it, see below:


Public Function FormatForSQL(ByVal strInput as string) as string)

If strInput is nothing then
Return ""
else
Return strInput
end if

end function

Dim value as string=FormatForSQL(request.params("some_value"))

 
Another thing you may want to do is to specify a default in your stored procedure:
Code:
Create proc spMySproc
   @my_param1  int
  ,@my_param2  varchar(20) = NULL
  ,@my_param3  int = 0

...

The "= NULL" and "= 0" specify defaults when the parameter is empty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top