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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:19:50+00:00 2026-06-18T04:19:50+00:00

I ran the SQL Query in SQL Server Management Studio and it worked. Here

  • 0

I ran the SQL Query in SQL Server Management Studio and it worked.

Here is my code

    private void buttonRunQuery_Click(object sender, EventArgs e)
     {
         if (connection == null)
         {
             connection = ConnectionStateToSQLServer();
             SqlCommand command = new SqlCommand(null, connection);
             command = createSQLQuery(command);
             dataGridView1.DataSource = GetData(command);
         }
         else
         {
             SqlCommand command = new SqlCommand(null, connection);
             command = createSQLQuery(command);
             dataGridView1.DataSource = GetData(command);
         }
     }

    private SqlCommand createSQLQuery(SqlCommand command)
     {
         string[] allTheseWords;
         if (textBoxAllTheseWords.Text.Length > 0)
         {
             allTheseWords = textBoxAllTheseWords.Text.Split(' ');
             string SQLQuery = "SELECT distinct [database].[dbo].[customerTable].[name], [database].[dbo].[customerTable].[dos], [database].[dbo].[customerTable].[accountID], [database].[dbo].[reportTable].[customerID], [database].[dbo].[reportTable].[accountID], [database].[dbo].[reportTable].[fullreport] FROM [database].[dbo].[reportTable], [database].[dbo].[customerTable] WHERE ";
             int i = 1;
             foreach (string word in allTheseWords)
             {
                 var name = "@word" + (i++).ToString();
                 command.Parameters.AddWithValue(name, "'%" + word "%'");
                 SQLQuery = SQLQuery + String.Format(" [database].[dbo].[reportTable].[fullreport] LIKE {0} AND ", name);
             }
             SQLQuery = SQLQuery + " [database].[dbo].[customerTable].[accountID] = [database].[dbo].[reportTable].[accountID]";
             command.CommandText = SQLQuery;
         }
         MessageBox.Show(command.CommandText.ToString());
         return command;
     }

    public DataTable GetData(SqlCommand cmd)
     {
         //SqlConnection con = new SqlConnection(connString);
         //SqlCommand cmd = new SqlCommand(sqlcmdString, cn);
         SqlDataAdapter da = new SqlDataAdapter(cmd);
         connection.Open();
         DataTable dt = new DataTable();
         da.Fill(dt);
         connection.Close();
         return dt;
     } 

No error is given by VS2012 and no data is presented in my DataGridView

Any suggestions?

I saw this website and it didn’t really help

http://bytes.com/topic/c-sharp/answers/530616-datagridview-combobox-column-databound-item-list

I am using an SQL Server 2012

The updated Query brings 1 single result in the SQL Server Management Studio (which is expected). The same query does not produce any rows in my datagrid.

I can’t figure out whats going on? Do I need to bind anything using the GUI for VS2012?

  • 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-18T04:19:52+00:00Added an answer on June 18, 2026 at 4:19 am

    I notice you’re doing a LIKE search, but when you’re adding your parameters, you’re not using “%”. Try adding this:

    command.Parameters.AddWithValue(name, "%" + word +"%");
    

    Hope this helps.

    BTW — The DataBind method is not used in win forms for gridviews, just in web forms.

    Good luck.

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

Sidebar

Related Questions

I ran a query on a MS SQL database using SQL Server Management Studio,
Possible Duplicate: sql server 2008 management studio not checking the syntax of my query
I ran this query on my SQL Server database: begin transaction; insert into [db].[a].[Table1]
I am using Microsoft SQL Server Management Studio. I have two databases one is
Here's the query that is being executed on SQL Server 2008: SELECT "dbo"."tblMainData"."recID" FROM
My SQL Server Management Studio suddenly went case sensitive on me. The database and
We have a query that takes 2 seconds to run in Sql Server Management
I ran this sql query in my database: update payments set method = 'paysafecard'
I just ran into a SQL query with about 5 different columns in the
I butter-fingered a query in SQL Server 2000 and added a period in the

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.