Using vbNull to insert NULL into a sql server database table
sql-server, vb.net
Solution
I believe you want `System.DbNull.Value` instead of `vbNull`.
`System.DbNull.Value` is the constant that SQL Server understands as null.
`vbNull` is intended to indicate if a Variant type is null.
Problem
I need to insert text MALE or FEMALE into a table depending upon the user's input. I used to following code to insert but the code inserts value 1 if none (Male/Female) selected. ``` query = "INSERT INTO student_profile_table(gender) VALUES(@gender)" cmd = New SqlCommand(query, con) If rbtmale.Checked = True Then cmd.Parameters.AddWithValue("@gender", "Male") ElseIf rbtfemale.Checked = True Then cmd.Parameters.AddWithValue("@gender", "Female") Else cmd.Parameters.AddWithValue("@gender", vbNull) End If con.Open() cmd.ExecuteNonQuery() con.Close() ``` Need some suggestions/corrections