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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:29:05+00:00 2026-06-08T23:29:05+00:00

Consider the following code: SqlConnection conn = new SqlConnection(@connection string); SqlCommand ourCommand = new

  • 0

Consider the following code:

SqlConnection conn = new SqlConnection(@"connection string");

SqlCommand ourCommand = new SqlCommand(String.Format(
    @"SELECT Field1,Field2,Field3 FROM Tbl WHERE Field1 LIKE '@FL1'"), conn);
ourCommand.CommandTimeout = 6000;

ourCommand.Parameters.AddWithValue("@FL1", TextBox1.Text);

SqlDataAdapter adapter = new SqlDataAdapter(ourCommand);
DataTable dt = new DataTable();

conn.Open();
adapter.Fill(dt);
GridView1.DataSource = dt;

GridView1.DataBind();

The problem is that datatable is empty – which means the command either was not executed or incorrect query was generated. What am I missing? Connection and query are valid. The command without parameter also works. Database engine is SQL Server 2008 R2

  • 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-06-08T23:29:08+00:00Added an answer on June 8, 2026 at 11:29 pm

    You’ve put the parameter name in quotes, so it’s being treated as a value, not as a parameter. Try this instead:

    "SELECT Field1,Field2,Field3 FROM Tbl WHERE Field1 LIKE @FL1"
    

    (I’d actually expect your existing code to throw an exception given that you’re supplying more parameters than are in the SQL…)

    As noted in comments, you don’t need the string.Format either.

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

Sidebar

Related Questions

Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
Consider the following code public class sqldetails extends JFrame implements ActionListener{ static String username=null;
Consider the following code: char* p = new char[2]; long* pi = (long*) p;
Consider following code for an android app; private String GetDistance(String src, String dest) {
Consider the following code: private static void GetData<TConnection, TCommand>( string connectionString, DataTable dataFromDbf, string
Consider following code: typedef SomeType type_t[2]; SomeType * arr1 = new type_t; //new or
Consider following code public class City { public string Name { get { return
Consider the following code, public class StartUp { public StartUp(String[] test){} public static void
Consider the following code snippet that takes user input (a date) and format it
Consider following code: Dim S1 As String = a 'this is the string in

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.