Results 1 to 2 of 2

Thread: [RESOLVED] SQL2012 Express - Trying to set two bits

  1. #1

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Resolved [RESOLVED] SQL2012 Express - Trying to set two bits

    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:
    1. Dim sqlCmd As New SqlCommand
    2.  
    3. sqlCmd.CommandText = "INSERT INTO MyTable_tbl (YourName_nvc, YesCol_bit, StillYesCol_bit) VALUES(@name, @yes, @still)"
    4. sqlCmd.Parameters.Add("@name", SqlDbType.NVarChar)
    5. sqlCmd.Parameters.Add("@yes", SqlDbType.Bit)
    6. sqlCmd.Parameters.Add("@still", SqlDbType.Bit)
    7.  
    8. For Each dt As DataRow In NewInvDT.Rows()
    9.     sqlCmd.Parameters("@name").Value = dt.Item(0).ToString()
    10.     sqlCmd.Parameters("@yes").Value = 1
    11.     sqlCmd.Parameters("@still").Value = 1
    12.     ' This is where I apply the sqlCmd to a Connection and executenonquery              
    13. 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:
    1. 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:
    1. 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?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  2. #2

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: SQL2012 Express - Trying to set two bits

    Nevermind, I finally figured it out. I forgot to turn off the "produce annoying results" property.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width