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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:28:05+00:00 2026-05-20T01:28:05+00:00

I have searched and tried different things for the past week or so and

  • 0

I have searched and tried different things for the past week or so and my problem is possibly to specific to find an answer through google.

If I execute this query in SQL Server Management Studio and replace the parameter @zoekterm with '%something%', it works fine and returns the result that I want. But when I call the same procedure from C# it returns nothing.

Is this a bug or am I just that stupid?

Here’s code of stored procedure and function in C#, (I know I should have used switch case…)

Stored procedure:

-- =============================================
-- Author:      Daan
-- Create date: 
-- Description: 
-- =============================================
ALTER PROCEDURE [dbo].[quick_bedrijf] 
    -- Add the parameters for the stored procedure here
    @zoekterm varchar(100) = 0
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT bedrijf.bedrijf_nr, bedrijf.zoeknaam, bedrijf.plaats
    FROM bedrijf
    WHERE zoeknaam LIKE @zoekterm AND NIETactief = 0

    ORDER BY bedrijf.zoeknaam, bedrijf.plaats 
END

C#:

private void snel_zoek2()
{
    listView1.Items.Clear();

    con.Open();
    if (type == 1)
    {
         command1 = new SqlCommand("quick_project", con);
         colnum = 5;
    }
    else if (type == 2)
    {
         command1 = new SqlCommand("quick_bedrijf", con);
         colnum = 3;
    }
    else if (type == 3)
    {
         command1 = new SqlCommand("quick_persoon", con);
         colnum = 4;
    }
    command1.CommandType = CommandType.StoredProcedure;
    SqlParameter zoekterm = command1.Parameters.Add("@zoekterm", SqlDbType.VarChar, 100);
    zoekterm.Direction = ParameterDirection.Input;
    //command1.Parameters.Add(new SqlParameter("@zoekterm", SqlDbType.VarChar)).Value = " '%zee%'";// + textBox2.Text.ToString()+
    zoekterm.Value = "'%"+textBox2.Text.ToString()+"%'";
    // MessageBox.Show(zoekterm.Value.ToString());
    SqlDataAdapter adapt = new SqlDataAdapter();
    DataTable dt = new DataTable();
    adapt.SelectCommand = command1;
    adapt.Fill(dt);
    dataGridView1.BindingContext = new BindingContext();
    dataGridView1.DataSource = dt;

    con.Close();
}
  • 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-20T01:28:06+00:00Added an answer on May 20, 2026 at 1:28 am

    You don’t put the quotes into the parameter (those are to signify a literal); it should be:

    zoekterm.Value = "%"+textBox2.Text+"%";
    

    It is failing currently because if the text is “abc”, it is looking for a string that starts and ends with a single quote and includes “abc”. In SQL terms, you were asking it for:

    LIKE '''%abc%'''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all, I have searched for this problem for long time and tried different methods.
I have searched and tried a bunch on different things. None have worked. What
I have searched here on SO and tried different solutions offered here, but cannot
I have searched a lot and tried much but I can not find the
I have searched through the full calendar documentation and tried a couple of solutions
I have searched high and low and tried multiple different solutions to this and
I've searched and searched and can't find an answer. Actually all the things I've
I have searched everywhere and tried mixing and matching different bits of code but
I have searched and tried every example regarding singleton, public, and global variables in
Yes, I have searched and tried many techniques, but nothing seems to work. Here

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.