No definition for Fill. (WinForms)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • M1kkelZU
    New Member
    • Feb 2013
    • 80

    No definition for Fill. (WinForms)

    Edit: I realized just now I misspelled Definition in the title... Sorry.

    I'm working on a personal project, where I have a database (SQLite) and a dataGridView.
    Now This is what I have:

    Code:
     public Form1()
            {
                DataSet ds = new DataSet();
                SqlConnection connection = new SqlConnection(@"Data Source=testingsql2.s3db");
                SqlDataAdapter SQLda = new SqlDataAdapter("Select * from User", connection);
                SqlCommandBuilder SQLcb = new SqlCommandBuilder(SQLda);
                dataGridView1.Fill(ds, "User"); //Error here
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "User";
            }
    I've marked where I get the error.

    And the Error description:
    Code:
    Error	1	'System.Windows.Forms.DataGridView' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)
    Anyone know what I could've done wrong?
  • Mikkeee
    New Member
    • Feb 2013
    • 94

    #2
    The DataGridView needs a datasource which you have set. The 'Fill' that your looking at is what adds or refreshes data to your dataset. So... you need to 'Fill' your dataset from the dataadapter and then assign the dataset to the gridview's datasource.

    Replace this:
    Code:
    dataGridView1.Fill(ds, "User"); //Error here
    With this:
    Code:
    SQLda.Fill(ds);

    Comment

    • M1kkelZU
      New Member
      • Feb 2013
      • 80

      #3
      Ah ok thanks it works now :)

      Comment

      Working...