Results 1 to 6 of 6

Thread: Inserting into Access Yes/No Field [Resolved]

  1. #1

    Thread Starter
    Member rabaile's Avatar
    Join Date
    May 2005
    Location
    Fayetteville, Arkansas
    Posts
    56

    Resolved Inserting into Access Yes/No Field [Resolved]

    I'm trying to insert a new row into a table and one of the fields I want to insert into is a Yes/No. I've tried inserting "Yes", "True", "Y". I get datatype mismatch each time. If I take it out of the statement, it works fine, so I know that is the problem field.

    Code:
    activeswitch = "True"

    Dim projectInsertFormat As String = "INSERT INTO project (CCN, ProjectName, Active, ActiveDate) " & _
    "VALUES('{0}', '{1}', '{2}', '{3}')"
    Dim projectInsert As String
    projectInsert = String.Format(projectInsertFormat, _
    txtccn.Text, _
    txtproject.Text, _
    activeswitch, _
    datehold)

    Active is the Yes/No Field in the DB. How should I recode this insert statement? Should the variable be string? Thanks.
    Last edited by rabaile; Jun 5th, 2005 at 08:04 PM.

  2. #2
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: Inserting into Access Yes/No Field

    When using SQL there is no such datatype as Yes | No

    It is in fact a Boolean field - of type True | False. Thus Your statement will look something like

    "INSERT INTO project (CCN, ProjectName, Active, ActiveDate) " & _
    "VALUES('0', 'TestProject', 'True', '" & Date.Now & ')"

  3. #3

    Thread Starter
    Member rabaile's Avatar
    Join Date
    May 2005
    Location
    Fayetteville, Arkansas
    Posts
    56

    Re: Inserting into Access Yes/No Field

    Dim projectInsertFormat As String = "INSERT INTO project (CCN, ProjectName, Active, ActiveDate) " & _
    "VALUES('{0}', '{1}', 'True', '{2}')"
    Dim projectInsert As String
    projectInsert = String.Format(projectInsertFormat, _
    txtccn.Text, _
    txtproject.Text, _
    datehold)

    This would be the same as your statement, just in my format. Still get datatype mismatch. Ideas?

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Inserting into Access Yes/No Field

    you need to change the txtproject.Text to CType(txtProject.Text, Boolean) for it to be passed as a boolean value, not a string.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Inserting into Access Yes/No Field

    You do not put single quotes around the True or False value. I don't know about other databases but I use Access almost exclusively and I never put single quotes around a boolean value when using it in an explicit SQL statement. Single quotes are for strings only.

  6. #6

    Thread Starter
    Member rabaile's Avatar
    Join Date
    May 2005
    Location
    Fayetteville, Arkansas
    Posts
    56

    Re: Inserting into Access Yes/No Field

    Taking the quotes off fixes it. Thanks so much!

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