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

The Archive Base Latest Questions

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

atm i am trying to write a code what will fill my DataGridView with

  • 0

atm i am trying to write a code what will fill my DataGridView with data from MySQL

string sql2Params = "Database=" + database + ";Data Source=" + host + ";User Id=" + user + ";Password=" + pass;
        string sql2Query = "SELECT * FROM `wagons` WHERE 1";

        //MySqlConnection sql2Connection = new MySqlConnection(sql2Params);
        //MySqlCommand sql2Command = new MySqlCommand(sql2Query, sql2Connection);

        using (MySqlConnection connection = new MySqlConnection(sql2Params))
        {
            connection.Open();
            using (MySqlCommand cmdSel = new MySqlCommand(sql2Query, connection))
            {
                DataTable dt = new DataTable();
                MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
                da.Fill(dt);
                wagonDataGrid.DataContext = dt;
            }
            connection.Close();
        }

I found this one, then checked in different web sites that its correct and trying to use in my own project, but i am getting error

Error   1   'System.Windows.Forms.DataGridView' does not contain a definition for 'DataContext' and no extension method 'DataContext' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)

What this can be?

  • 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:32:21+00:00Added an answer on June 8, 2026 at 11:32 pm

    use DataSource isntead of DataContext, no property DataContext in winform datagrid

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

Sidebar

Related Questions

ATM I am trying to learn how to efficiently use database inidices and would
I am trying to write a method that reads a list from file1, search
I'm trying to retrive some data from a web site . I wrote a
im learning RoR atm and im trying to code a calculator webapp. The thing
I am trying to get the jQuery autocomplete widget to get the data from
I've been working on trying to write a function that will grab the POST
I am using MYSQL 5.1, I am trying to write an insert statement in
Please excuse poor code atm, just trying to get it working before making it
I'm trying to run an ATM Simulation in C# with Windows Forms that can
ATM i cant quiet imagine how this will work. I'm sure it can be

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.