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

  • Home
  • SEARCH
  • 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 4077456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:33:09+00:00 2026-05-20T17:33:09+00:00

I call this method on form load ivent GetProducts( ); This Query works fine

  • 0

I call this method on form load ivent GetProducts(” “);
This Query works fine in sql. It was working till i added WHERE
When i use debugger on this line >> SqlDataReader myReader = cmd.ExecuteReader();
Can anyone advice me something?

 public void GetProducts(string find)
    {
        try
        {
            using (SqlCommand cmd = new SqlCommand("SELECT ID, BarCode, ArtNumber, ProductName, Price, SelfPrice, PriceWithOutAWD, TotalSelfPrice, UnitsInStock, " +
                                                " Comment, InputDateTime, InputQuantity, Margin, CategoryName, TypeName, ExpDate FROM GetProducts"+
                                                "WHERE BarCode LIKE '%@F%' OR ArtNumber LIKE '%@F%' OR ProductName LIKE '%@F%' OR Price LIKE '%@F%' OR Comment LIKE '%@F%' ", 
                                                new SqlConnection(Program.ConnectionString)))
            {
                cmd.Parameters.AddWithValue("@F", find);
                cmd.Connection.Open();

                SqlDataReader myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {

                    ProductTable.Rows.Add
                        (
                        (int)myReader["ID"],
                        myReader["BarCode"].ToString(),
                        myReader["ArtNumber"].ToString(),
                        myReader["ProductName"].ToString(),
                        (decimal)myReader["Price"],
                        (decimal)myReader["SelfPrice"],
                        (decimal)myReader["PriceWithOutAWD"],
                        myReader["TotalSelfPrice"].ToString(),
                        myReader["UnitsInStock"].ToString(),
                        myReader["Comment"].ToString(),
                        myReader["InputDateTime"].ToString(),
                        myReader["InputQuantity"].ToString(),
                        myReader["Margin"].ToString(),
                        myReader["CategoryName"].ToString(),
                        myReader["TypeName"].ToString(),
                        myReader["ExpDate"].ToString()
                        );
                }
                cmd.Connection.Close();
            }
        }
        catch (Exception)
        {
            MessageBox.Show(Program.MsgError1, "Acid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

    }
  • 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-20T17:33:10+00:00Added an answer on May 20, 2026 at 5:33 pm
    ... FROM GetProducts"+
    "WHERE BarCode LIKE ...
    

    Should be (note additional space between GetProducts and WHERE)

    ... FROM GetProducts "+
    "WHERE BarCode LIKE ...
    

    Also don’t use

    WHERE BarCode LIKE '%@F%'
    

    Either Use

    WHERE BarCode LIKE '%' + @F + '%' 
    

    Or alternatively have the parameter value contain the wild cards and use

    cmd.Parameters.AddWithValue("@F", "%" + find + "%"); 
     ...
    WHERE BarCode LIKE @F
    

    If you will always be searching with a leading wildcard however you should probably use

    WHERE CHARINDEX(@F,BarCode) > 0
    

    Your query won’t be able to use an index anyway and this method avoids issues if the users search for substrings that contain characters that have a special meaning in the pattern syntax.

    However from the amount of columns you are searching and the leading wildcards you should probably use full text indexing for this anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my view controller's -viewDidLoad method, I call [myTextField becomeFirstResponder]; This works like a
Every time I call this method my NSMutableData is leaking and I cannot figure
I'd like to accomplish something like this: Call a method, say turn, and then
This is my first time attempting to call an ASP.NET page method from jQuery.
This code involves a recursive Stored Procedure call and a not so great method
When you call the object.__repr__() method in Python you get something like this back:
This question is a follow up to: Why can’t I call a method outside
I got this question from this discussion . A method call like object.m does
When I call this function, everything works, as long as I don't try to
I have a JavaScript function, pop_item . I have to call this from PHP,

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.