This is driving me crazy:
I'm trying to insert records into a SQL 2012 Express database by specifying the columns of data. Two of the columns are bits and both receive the same value. However, at runtime only one of them actually gets set in the database even though the columns are set up identically.
vb.net Code:
Dim sqlCmd As New SqlCommand
sqlCmd.CommandText = "INSERT INTO MyTable_tbl (YourName_nvc, YesCol_bit, StillYesCol_bit) VALUES(@name, @yes, @still)"
sqlCmd.Parameters.Add("@name", SqlDbType.NVarChar)
sqlCmd.Parameters.Add("@yes", SqlDbType.Bit)
sqlCmd.Parameters.Add("@still", SqlDbType.Bit)
For Each dt As DataRow In NewInvDT.Rows()
sqlCmd.Parameters("@name").Value = dt.Item(0).ToString()
sqlCmd.Parameters("@yes").Value = 1
sqlCmd.Parameters("@still").Value = 1
' This is where I apply the sqlCmd to a Connection and executenonquery
Next
When I run the code, each record gets added without errors, except that YesCol_bit = 1 and StillYesCol_bit = 0, but they should both be the same.
I have tried doing this:
vb.net Code:
sqlCmd.CommandText = "INSERT INTO MyTable_tbl (YourName_nvc, YesCol_bit, StillYesCol_bit) VALUES(@name, 1, 1)"
This gets the exact same results where YesCol_bit = 1 and StillYesCol_bit = 0.
I have even tried setting the default value for both columns to 1 and just doing this:
vb.net Code:
sqlCmd.CommandText = "INSERT INTO MyTable_tbl (YourName_nvc) VALUES(@name)"
Still same result.
What's even more aggravating is if I run the commands from query editor in SQL Server Management Studio, they all complete excactly as they should.
Has anyone seen this before?