Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. boolean in SQL

boolean in SQL

Scheduled Pinned Locked Moved Visual Basic
questiondatabasehelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DaveC426913
    wrote on last edited by
    #1

    What is wrong with this code? Structure PP Public Name As String Public Archive As **Boolean** End Structure Public Sub Inst() Dim AddPP As New PP With AddPP .Name = txtPPName.Text **.Archive = True** End With cmd = "INSERT INTO Pub_Points (PPName,Archive) VALUES ('" + AddPP.Name + "'," + **AddPP.Archive** + ")" End Sub It chokes with 'System.FormatException: Input string was not in a correct format.' This is my current kluge: cmd = "INSERT INTO Pub_Points (PPName,Archive) VALUES ('" + AddPP.Name + "'," " + **CInt(AddPP.Archive).ToString** + ")" But what is the point in defining a property as boolean if I have to convert it back to string to use it? ________________________________________________________________________ Dave Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002) -- modified at 17:20 Tuesday 6th September, 2005

    C 1 Reply Last reply
    0
    • D DaveC426913

      What is wrong with this code? Structure PP Public Name As String Public Archive As **Boolean** End Structure Public Sub Inst() Dim AddPP As New PP With AddPP .Name = txtPPName.Text **.Archive = True** End With cmd = "INSERT INTO Pub_Points (PPName,Archive) VALUES ('" + AddPP.Name + "'," + **AddPP.Archive** + ")" End Sub It chokes with 'System.FormatException: Input string was not in a correct format.' This is my current kluge: cmd = "INSERT INTO Pub_Points (PPName,Archive) VALUES ('" + AddPP.Name + "'," " + **CInt(AddPP.Archive).ToString** + ")" But what is the point in defining a property as boolean if I have to convert it back to string to use it? ________________________________________________________________________ Dave Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002) -- modified at 17:20 Tuesday 6th September, 2005

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      DaveC426913 wrote: But what is the point in defining a property as boolean if I have to convert it back to string to use it? You do have to convert it into a string, it's a string because it's part of cmd, which is a string. VB is doing this for you implicitly in the first instance. What does cmd look like in the debugger in the first instance ? What's the type of the Archive column in the database ? If you go into Query Analyser, what changes do you need to make to the string in cmd in the first instance, for it to work ? Christian Graus - Microsoft MVP - C++

      D 1 Reply Last reply
      0
      • C Christian Graus

        DaveC426913 wrote: But what is the point in defining a property as boolean if I have to convert it back to string to use it? You do have to convert it into a string, it's a string because it's part of cmd, which is a string. VB is doing this for you implicitly in the first instance. What does cmd look like in the debugger in the first instance ? What's the type of the Archive column in the database ? If you go into Query Analyser, what changes do you need to make to the string in cmd in the first instance, for it to work ? Christian Graus - Microsoft MVP - C++

        D Offline
        D Offline
        DaveC426913
        wrote on last edited by
        #3

        "You do have to convert it into a string, it's a string because it's part of cmd, which is a string." Did you mean *I do* or *I do not* have to? "What does cmd look like in the debugger in the first instance ?" It doesn't. It chokes trying to parse that line of code. This isn't a db problem, it's a VB problem. "What's the type of the Archive column in the database ?" Sorry, it is bit. "If you go into Query Analyser, what changes do you need to make to the string in cmd in the first instance, for it to work?" Well, I have to change T/F to 1/0, which is what I'm doing. Which brings me back to my question: why am I bothering to Dimension it as boolean? A thought: Should my structure have a get/set that automatically converts between T/F and 0/1? ________________________________________________________________________ Dave Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002) -- modified at 9:13 Wednesday 7th September, 2005

        C 1 Reply Last reply
        0
        • D DaveC426913

          "You do have to convert it into a string, it's a string because it's part of cmd, which is a string." Did you mean *I do* or *I do not* have to? "What does cmd look like in the debugger in the first instance ?" It doesn't. It chokes trying to parse that line of code. This isn't a db problem, it's a VB problem. "What's the type of the Archive column in the database ?" Sorry, it is bit. "If you go into Query Analyser, what changes do you need to make to the string in cmd in the first instance, for it to work?" Well, I have to change T/F to 1/0, which is what I'm doing. Which brings me back to my question: why am I bothering to Dimension it as boolean? A thought: Should my structure have a get/set that automatically converts between T/F and 0/1? ________________________________________________________________________ Dave Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002) -- modified at 9:13 Wednesday 7th September, 2005

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          DaveC426913 wrote: Did you mean *I do* or *I do not* have to? You *do*. the variable cmd is a string. Therefore, you have to turn whatever you pass through into a string, to make it part of the string command. DaveC426913 wrote: It doesn't. It chokes trying to parse that line of code. This isn't a db problem, it's a VB problem. OK, in that case, VB isn't magically turning your boolean into a string, call it's .ToString method to get what you need. DaveC426913 wrote: Well, I have to change T/F to 1/0, which is what I'm doing. Query Analyzer needs a 1 or 0, not true or false ? In that case, does VB support ? : notation ? As in myBool ? 1 : 0, returns 1 if myBool is true, otherwise returns false ? DaveC426913 wrote: A thought: Should my structure have a get/set that automatically converts between T/F and 0/1? I'd try to do it inline. Or, if you used stored procedures, you can pass them a bool as a parameter, and the SP will turn it into what is needed. That's what I do, which is why I wasn't sure if SQL Server accepts true/false as bit values. Christian Graus - Microsoft MVP - C++

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups