CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: SQL Question

  1. #1
    Join Date
    Oct 1999
    Location
    Nova Scotia Canada
    Posts
    3

    SQL Question

    I am writing a program using a MS Office Database and a visual basics program to run it. What I am trying to do is to have the students write in the name of a student that they want, and have the program post the E mail name for that student. The name of the database is "student" the field that I am searching is called "Name", and the code that I am trying to use looks like:

    Data1.RecordSource = "Select * from students where Name = txtname.text "
    Data1.Refresh

    txtname.text is the text box where I want the students to write the name of the student that they are looking for. If you can help it would be greatly appriciated. Thanks.


  2. #2
    Guest

    Re: SQL Question

    Replace with this:

    Data1.RecordSource = "Select * from students where Name = " & txtname.text



    Vlad


  3. #3
    Guest

    Re: SQL Question

    If it's a text field, you'll likely have to enclose the field value with single quotes:


    Data1.RecordSource = "Select * from students where Name = '" & txtname.text & "'"




    Good luck,

    Mike


  4. #4
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: SQL Question

    Hi,
    Change the statement -
    "Select * from students where Name = txtname.text "
    to

    "Select * from students where Name = '" & txtname.text & "'"





    good luck :-)

    Santulan

  5. #5
    Join Date
    Oct 1999
    Location
    Nova Scotia Canada
    Posts
    3

    Re: SQL Question

    Thanks for the help, it worked great!


  6. #6
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    115

    Re: SQL Question

    If you are going to do it this way, you should be aware that names with an apostrophe in them like O'hara will cause a runtime error (the single apostrophe tells the database that you have ended the text field). Move the text to a VB string and then replace all instances of apostrophe with two apostrophe. This will tell the SQL engine that you are selecting/updating/inserting/deleting a text object with an single apostrophe.


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

Featured