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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:40:25+00:00 2026-06-13T05:40:25+00:00

I have a problem with stored procedures. This code works (with a ListBox )

  • 0

I have a problem with stored procedures.

This code works (with a ListBox)

private void button4_Click(object sender, EventArgs e)
{
   string connectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
   SqlConnection connection = new SqlConnection(connectionString);

   string sqlCmd = "Drie duurste producten";

   SqlCommand cmd = new SqlCommand(sqlCmd, connection);

   cmd.CommandType = CommandType.StoredProcedure;
   cmd.CommandText = sqlCmd;

   connection.Open();

   using (SqlDataReader reader = cmd.ExecuteReader())
   {
      while (reader.Read())
      {
          listBox1.Items.Add(reader.GetValue(0).ToString()); 
      }
   }   

   connection.Close();
}

But how can I add this data to a DataGridView instead of a ListBox?

Thank you!

  • 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-13T05:40:26+00:00Added an answer on June 13, 2026 at 5:40 am

    Change to

       ......
       using (SqlDataAdapter adapter = new SqlDataAdapter()) 
       { 
            DataTable dt = new DataTable();
            adapter.SelectCommand = cmd;            { 
            adapter.Fill(dt);
            dataGridView1.DataSource = dt;
       }    
       ......
    

    usually a DataGridView is filled binding a complete datasource to its DataSource property and letting the control to figure out how to configure its columns and the formatting of the values displayed

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

Sidebar

Related Questions

I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
Im create this code to store page view in database, but i have problem
if you have not encountered this problem and I have to upload my code
I have a stored procedure which looks like this: USE [DBName] GO /****** Object:
I have a problem when debugging stored procedure using SQL server Management Studio 2008.
I have problem with my query on C, I’m using the oci8 driver. This
On our production SQL2000 instance, we have a database with hundreds of stored procedures,
I have the following scenario: We have stored procedures which compare our developement database
I have tried solving this problem by posting other related questions here that focused
I have been looking for a solution to this problem for a while now

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.