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 6020501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:34:41+00:00 2026-05-23T03:34:41+00:00

I am using C#.net Windows form , and I need to create a search

  • 0

I am using C#.net Windows form , and I need to create a search textbox which will display combo box values (similar to google search); The values displayed in the combo box will be values from the SQL 2005 database (example the user is searching on FirstName, the combobox will display all firstnames, which get filtered as the user types in more letters…. if user is searching on LastName, the combo box displays all LastName values in the database.. etc)

when I am doing the above task

I have written the sql query like this

SELECT  distinct(person_Firstname+''+person_Lastname) 
AS 
name FROM persondetails 
WHERE name Like '%'+@name+'%'

when I am executing this query it gives error like this — must declare a scalar varaible

my aim is when i am entering first letter in textbox it will display all names starting with that letter like in google…

can any one correct this ….

private void tbautocomplete_TextChanged(object sender, EventArgs e)
{
    AutoCompleteStringCollection namecollection = new AutoCompleteStringCollection();
    SqlConnection con = new SqlConnection(@"Data Source=88888;Initial Catalog=contrynames;Integrated Security=True");
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT  distinct(person_Firstname+''+person_Lastname) AS name FROM persondetails WHERE name Like '%'+@name+'%'";
    con.Open();
    SqlDataReader rea = cmd.ExecuteReader();
    if (rea.HasRows == true)
    {
        while (rea.Read())
        namecollection.Add(rea["name"].ToString());            
    }
    rea.Close();

    tbautocomplete.AutoCompleteMode = AutoCompleteMode.Suggest;
    tbautocomplete.AutoCompleteSource = AutoCompleteSource.CustomSource;
    tbautocomplete.AutoCompleteCustomSource = namecollection;
  • 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-05-23T03:34:42+00:00Added an answer on May 23, 2026 at 3:34 am

    It sounds like you’re trying to build an AutoComplete feature in your app. You’re only missing the parameter on your SqlCommand. Try this:

    string searchFor = "%" + txtName.Text + "%"; //the string the user entered.
    
    cmd.CommandText = @"SELECT  distinct(person_Firstname+''+person_Lastname) AS name
                        FROM persondetails 
                        WHERE person_Lastname Like @name
                        OR person_Firstname LIKE @name";
    
    cmd.Parameters.AddWithValue("@name", searchFor);
    

    Your WHERE clause must use the column name in your table. It sounds as if you want to match either the first or last name columns with your search token.

     WHERE person_Lastname LIKE @name
        OR person_Firstname LIKE @name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using .NET Remoting. My server/hoster is a Windows Service. It will sometimes
I need to create a full-text search form for a database of emails /
I am building a Windows form application using .NET 3.5. I would like to
I need to create a web application using ASP.NET MVC, jQuery and web standards
All I have built a windows form application using VS 2005 Standard edition which
I'm using Windows Vista and Visual Studio 2010. Create a .Net 4 Windows Forms
We are developing C#.Net 4.0 Windows form based application using Microsoft.Office.Interop.Word reference. Now I
We are developing C# .net 4.0 Windows Form Based Application. Here, User Will enter
I have a windows form application(c#) and an asp.NET web application which both access
I'm implementing a email newsletter sender service using .NET and Windows Server technologies. Are

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.