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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:24:46+00:00 2026-05-18T05:24:46+00:00

I have written a code that searches specific string from database table.what i want

  • 0

I have written a code that searches specific string from database table.what i want to implement is search like when we search friends on facebook means it returns results matching to the input given even if it is partial
for example if i want to search ANDREW as soon as i enter single character results should start to appear if i enter “an” like
andy
andrew
and….

here is my code for textbox text changed method

    table = new DataTable();
    table.Columns.Add("Name");
    table.Columns.Add("Type");
    table.Columns.Add("Status");
    table.Columns.Add("Date Created");
    table.Columns.Add("Action");

    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = textBoxSearch.Text;
    cmd.CommandText = "SELECT id,uName,uType,uStatus,uDate from users WHERE uName=@username ";

    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows == true)
    {
        while (dr.Read())
        {
            MessageBox.Show(dr["uName"].ToString() + dr["uType"].ToString() + dr["uStatus"].ToString());
            row = table.NewRow();
            row["Name"] = dr["uName"].ToString();
            row["Type"] = dr["uType"].ToString();
            row["Status"] = dr["uStatus"].ToString();
            row["Date Created"] = dr["uDate"].ToString();
            // row["Action"] = new Button();
            table.Rows.Add(row);
            UsersView.DataSource = table;
        }//End While for entering peresent amount of data                   
    }//End If to check wether or not users exist
    dr.Close();//Close Datareader
}
  • 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-18T05:24:46+00:00Added an answer on May 18, 2026 at 5:24 am

    As you’re using C#, why not go for something more LINQ-y?

    Set up your LINQ Database Context file and use the following code to achieve what you’re trying to (quickly typing this, sorry if there’s any errors):

    table = new DataTable();
    table.Columns.Add("Name");
    table.Columns.Add("Type");
    table.Columns.Add("Status");
    table.Columns.Add("Date Created");
    table.Columns.Add("Action");
    
    var db = new DbDataContext();
    var users = (from u in db.users
                 where u.Contains(textBoxSearch.Text)
                 select u).ToList();
    foreach(var user in users)
    {
         MessageBox.Show(user.uName + user.uType + user.uStatus);
                row = table.NewRow();
                row["Name"] = user.uName;
                row["Type"] = duser.uType;
                row["Status"] = user.uStatus;
                row["Date Created"] = user.uDate.ToShortDateString();
                table.Rows.Add(row);
    }
    
    UsersView.DataSource = table;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code that automatically creates CSS sprites based on the IMG tags
Put it another way: what code have you written that cannot fail. I'm interested
I have a code snippet written in PHP that pulls a block of text
We’ve found that the unit tests we’ve written for our C#/C++ code have really
Here's a snippet of code from a shell script I have written: for src
I have just been re-working an old bit of compiler-like code written using bison.
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have written a few modules of code in Access vba. Each code runs
I have some code I've written in PHP for consuming our simple webservice, which

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.