Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:47:57+00:00 2026-06-18T12:47:57+00:00

I am developing a search engine within WindowsForms, I’m using VB.Net 2010 and SQL

  • 0

I am developing a search engine within WindowsForms,
I’m using VB.Net 2010 and SQL Server 2008,
My connection is ADO.Net

I experience difficulties in concatenating strings whenever I retrieve records from the database using a textbox, combobox and a radiobutton.

I would like to retrieve record based from the values of those objects,

Dim Condition1 As String = TextBox1.Text
Dim Condition2 As String = ComboBox1.Text
Dim Condition3  As String = RadioButton.Text

When I try to concatenate, I use the operator AND..

SELECT * FROM TableName WHERE (Condition1 AND Condition2 AND Conditon3)

It gives me an error when some objects doesnt have a value.

Incorrect syntax near the word AND.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:47:58+00:00Added an answer on June 18, 2026 at 12:47 pm

    NEVER concatenate strings to make queries! use SQL Parameters! The query you posted is prone to SQL Injection.

    Dim query as String = "SELECT * FROM TableName WHERE Column1 = @Column1 AND 
                                 Column2 = @Column2 AND Column3 = @Column3"
    Dim cmd As SqlCommand
    cmd.Parameters.AddWithValue("@Column1", textBox1.Text)
    cmd.Parameters.AddWithValue("@Column2", comboBox1.Text)
    cmd.Parameters.AddWithValue("@Column3", radioButton1.Text)
    

    Apart from the above, the conditions you are trying to concatenate are not valid. Anything that comes after the WHERE clause should specify the column name and the value like what I did above. So condition1 should be for example :

    // If the column type is varchar then single quotes must be used
    Dim Condition1 As String = String.Format("Name = '{0}'", TextBox1.Text)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Desktop Search Engine in Visual Basic 9 (VS2008) using Lucene.NET (v2.0).
I'm developing a Desktop Search Engine using VB9 (VS2008) and Lucene.NET. The Indexer in
I'm developing a Desktop Search Engine in VB.NET and I'm looking for a powerful,
I am thinking of developing a web search engine using Erlang, Mnesia & Yaws.
I'm developing a search engine for a CCG. I want the user to be
I'm currently developping a search engine using Solr for an ecommerce website. So I
I am developing a live search system using Ajax and PHP and it is
I am developing a search engine in java.It works fine but all results are
I'm developing a search engine which functions taking the semantics of data into account,
I am developing a search engine. I am thinking about taking unique words from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.