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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SqlParameters to Null

Status
Not open for further replies.

toetag

MIS
Sep 27, 2002
166
US
As the title says, I'm trying to set an SqlParameter to null. Everytime my "id" = 0 I want the value to be sent as null. My guess apparently is wrong if you note the below code. With or without quotes the id = null; just doesn't work. Each time I get a message that @ID is expected by the SP and wasn't supplied.

Any Suggestions?

Code:
[b]
			SqlParameter[] parameters = 
				{
					new SqlParameter("@ID", SqlDbType.Int, 4),
					new SqlParameter("@ClientID", SqlDbType.Int, 4),
					new SqlParameter("@PersonnelID", SqlDbType.Int, 4)
				};
			if (id != 0)
			{
				parameters[0].Value = id;
			}
			else
			{
				parameters[0].Value = null;
			}
[/b]
 
20 seconds after I hit submit i found:

SqlInt32.Null

My apologizes for wasting the forums time.
 
Glad you found the answer!

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top