how do I set a SQLdataAdapter's insert parameter to NULL

  • Thread starter Thread starter Larry
  • Start date Start date
L

Larry

In my application I use a field of SQL type bit as a kind of tri-state
indicater; 0, 1, and null. When I insert the record into the database using
a stored procedure I set all the parameters and preform an executeNonQuery.

My problem is that I want to be able to set this one parameter under a given
condition to null initially but I can not find a way to add the parameter
and have the insert work under ADO.NET

here's what I'm trying (although I know it's not working):

Dim spcmd As SqlClient.SqlCommand

spcmd = New SqlClient.SqlCommand("spInsertUserActivity2", Me.SqlConnection2)

spcmd.CommandType = CommandType.StoredProcedure

Dim param As SqlClient.SqlParameter

' set up the parameter values.....

If Me.ddAddAssign2.SelectedItem.Text = owner Then

param = spcmd.Parameters.Add("@accepted", 1)

Else

param = spcmd.Parameters.Add("@accepted", Nothing) ' <<< this is where I
wanted to set the value to DBNULL

End If

' try to do the insert .....

Me.SqlConnection2.Open()

spcmd.ExecuteNonQuery()

Me.SqlConnection2.Close()



This should be an easy answer I would think. but I haven't found a reference
as to what this constant is called.

Is there one, and if so what is it called?

-Larry
 
Hi Larry,

I think Prodip's suggestion is quite correct and here are some further
references which will also be helpful:

#DBNull Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDBNullClassTop
ic.asp?frame=true

#Best Practices for Using ADO.NET
http://msdn.microsoft.com/library/en-us/dnadonet/html/adonetbest.asp?frame=t
rue

Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Hi Larry,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top