boolean in SQL
-
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 -
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, 2005DaveC426913 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++
-
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++
"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
-
"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
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++