Solved

Syntax error converting the varchar value 'True' to a column of data type bit.......Attempting to use the Cbool command

Posted on 2004-09-15
2
272 Views
Last Modified: 2011-09-20
I am attempting to read a value that is either a 1 or 0.  I want to save it in a SQL database as a Boolean value.  Any ideas on what I am doing wrong.

Thanks
Kenny

Here is my code

Syntax error converting the varchar value 'True' to a column of data type bit.




Here is the code

Database structure field is set to bit as the type


Dim migrant As String



migrant = Mid(strLine, 102, 1)

Try
                'Insert Records into StudentInfo
                Dim objConnection7 As SqlConnection = New SqlConnection("server=(local);database=FBISD-TAKS;user id=sa;password=pa55word")
                Dim objCommand7 As SqlCommand = New SqlCommand
                objCommand7.Connection = objConnection7
                objCommand7.CommandText = "Insert Into studentInfo " & "(admDate,grade,studentId, esc, lname, fname, mi, sex, dob, ethnicity, ecoDis, title1, migrant, lep) " & _
                            "VALUES(@iadmDate,@grade,@studentId, @esc, @lname, @fname, @mi, @sex, @dob, @ethnicity, @ecoDis, @title1, @migrant, @lep)"
                objCommand7.Parameters.Add("@iadmDate", SqlDbType.DateTime, 10).Value = madmDate
                objCommand7.Parameters.Add("@grade", SqlDbType.Int, 4).Value = grade
                objCommand7.Parameters.Add("@studentid", SqlDbType.Int, 4).Value = Val(studentId)
                objCommand7.Parameters.Add("@esc", SqlDbType.Int, 4).Value = Val(esc)
                objCommand7.Parameters.Add("@lname", SqlDbType.VarChar, 14).Value = lname.Trim
                objCommand7.Parameters.Add("@fname", SqlDbType.VarChar, 14).Value = fname.Trim
                objCommand7.Parameters.Add("@mi", SqlDbType.VarChar, 2).Value = mi.Trim
                objCommand7.Parameters.Add("@sex", SqlDbType.VarChar, 1).Value = sex
                objCommand7.Parameters.Add("@dob", SqlDbType.DateTime, 10).Value = mdob
                objCommand7.Parameters.Add("@ethnicity", SqlDbType.Int, 4).Value = Val(ethnicity)
                objCommand7.Parameters.Add("@ecoDis", SqlDbType.Int, 4).Value = Val(ecoDis)
                objCommand7.Parameters.Add("@title1", SqlDbType.Int, 4).Value = Val(title1)
                objCommand7.Parameters.Add("@migrant", SqlDbType.Bit, 1).Value = CBool(migrant)
0
Comment
Question by:kwh3856
2 Comments
 
LVL 16

Accepted Solution

by:
RobertRFreeman earned 500 total points
ID: 12070103
Try using cint(cbool(migrant)).
0
 

Author Comment

by:kwh3856
ID: 12092631
Robert,
Thanks for the help
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now