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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:12:14+00:00 2026-05-23T18:12:14+00:00

How can I rewrite this so that it is using parameters instead of string

  • 0

How can I rewrite this so that it is using parameters instead of string values? I know how to do it for an “SqlCommand”, but I can’t seem to work it out here.

    protected void searchFill()
    {
        orderByString = orderByList.SelectedItem.Value;
        fieldString = searchTextBox.Text;
        string sqlStatement = "SELECT * FROM SecureOrders WHERE fName LIKE @fieldString OR lName LIKE @fieldString OR addr LIKE @fieldString OR addr2 LIKE @fieldString OR city LIKE @fieldString OR state LIKE @fieldString OR zip LIKE @fieldString OR zip LIKE @fieldString OR country LIKE @fieldString OR email LIKE @fieldString OR phone LIKE @fieldString OR ccType LIKE @fieldString OR ccNum LIKE @fieldString OR ccExp LIKE @fieldString OR cwaSource LIKE @fieldString OR cwaJoined LIKE @fieldString OR length LIKE @fieldString OR delivery LIKE @fieldString OR price LIKE @fieldString OR url LIKE @fieldString ORDER BY @orderByString";
        using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
        {
            connection.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlStatement, connection);
            dataAdapter.SelectCommand.Parameters.AddWithValue("@fieldString", fieldString);
            dataAdapter.SelectCommand.Parameters.AddWithValue("@orderByString", orderByString);
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
            DataSet dataSet = new DataSet();

            dataAdapter.Fill(dataSet, "SecureOrders");

            DataView source = new DataView(dataSet.Tables[0]);
            DefaultGrid.DataSource = source;
            DefaultGrid.DataBind();
            connection.Close();
        }
    }

Here is my other method where I AM using parameters (just to show you I do know how to use them slightly)

    protected void updateCheck(bool checkValue, int identity)
    {
        string checkStatement = "UPDATE dbo.SecureOrders SET processed = @Processed WHERE IdentityColumn LIKE @identity";
        using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
        using (SqlCommand _check = new SqlCommand(checkStatement, connection))
        {
            _check.Parameters.Add("@Processed", SqlDbType.Bit).Value = checkValue;
            _check.Parameters.Add("@identity", SqlDbType.Int).Value = identity;
            connection.Open();
            _check.ExecuteNonQuery();
            connection.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-23T18:12:15+00:00Added an answer on May 23, 2026 at 6:12 pm

    Instances of SqlDataAdapter have a property called SelectCommand that you can attach parameters to:

    var dataAdapter = new SqlDataAdapter(someQuery, someConnection);
    dataAdapter.SelectCommand.Parameters.AddWithValue("@someParam", someVar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an attempt to rewrite some old homework using STL algorithms instead of
I know you can do redirection based on the domain or path to rewrite
Does anyone have experience using the URL Rewrite Module (see here )? Can it
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can anyone explain what this mod_rewrite rule is doing? I'm trying to comment the
How can I rewrite or is there a way to writing my own custom
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
sigh I'm sorry to say that I'm using Intel IPL (Image Processing Library) in
I'm about to have to rewrite some rather old code using SQL Server's BULK

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.