Avatar billede joki Mester
23. december 2005 - 19:06 Der er 4 kommentarer og
1 løsning

Kan ikke finde DataBind()

Hej

Jeg har et DataGridView hvor datasource er sat til tabel i dataset.
Jeg kan ikke finde Databind() metoden og dermed fylde mit gridview
Nogen der kan hjælpe. AutoGenerateColumns er sat til true.

this.filmDataGridView.DataSource = r.Tables[0];
// Her går det galt

this.filmDataGridView.DataBind()
Avatar billede Syska Mester
23. december 2005 - 20:19 #1
Det burde virke sådan.....

            string[] array = new string[] { "test1", "test2","test3","test4","test5"};
            dataGridView1.DataSource = array;

Virker hos mig :-)
Avatar billede Syska Mester
23. december 2005 - 20:21 #2
Har også testet med dataset, table.... ingen problem...

Der må være noget andet galt

// ouT
Avatar billede Slettet bruger
24. december 2005 - 06:39 #3
Eksempel fra doc...

private void GetData(string selectCommand)
{
    try
    {
        // Specify a connection string. Replace the given value with a
        // valid connection string for a Northwind SQL Server sample
        // database accessible to your system.
        String connectionString =
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";

        // Create a new data adapter based on the specified query.
        dataAdapter = new SqlDataAdapter(selectCommand, connectionString);

        // Create a command builder to generate SQL update, insert, and
        // delete commands based on selectCommand. These are used to
        // update the database.
        SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

        // Populate a new data table and bind it to the BindingSource.
        DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        dataAdapter.Fill(table);
        bindingSource1.DataSource = table;

        // Resize the DataGridView columns to fit the newly loaded content.
        dataGridView1.AutoResizeColumns(
            DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
    }
    catch (SqlException)
    {
        MessageBox.Show("To run this example, replace the value of the " +
            "connectionString variable with a connection string that is " +
            "valid for your system.");
    }
}


C++  Copy Code
private:
    void GetData(String^ selectCommand)
    {
        try
        {
            // Specify a connection string. Replace the given value with a
            // valid connection string for a Northwind SQL Server sample
            // database accessible to your system.
            String^ connectionString =
                "Integrated Security=SSPI;Persist Security Info=False;" +
                "Initial Catalog=Northwind;Data Source=localhost";

            // Create a new data adapter based on the specified query.
            dataAdapter = gcnew SqlDataAdapter(selectCommand, connectionString);

            // Create a command builder to generate SQL update, insert, and
            // delete commands based on selectCommand. These are used to
            // update the database.
            gcnew SqlCommandBuilder(dataAdapter);

            // Populate a new data table and bind it to the BindingSource.
            DataTable^ table = gcnew DataTable();
            dataAdapter->Fill(table);
            bindingSource1->DataSource = table;

            // Resize the DataGridView columns to fit the newly loaded content.
            dataGridView1->AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode::AllCellsExceptHeader);
        }
        catch (SqlException^)
        {
            MessageBox::Show("To run this example, replace the value of the " +
                "connectionString variable with a connection string that is " +
                "valid for your system.");
        }
    }



In your form's Load event handler, bind the DataGridView control to the BindingSource component and call the GetData method to retrieve the data from the database.

Visual Basic  Copy Code
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.Load

    ' Bind the DataGridView to the BindingSource
    ' and load the data from the database.
    Me.dataGridView1.DataSource = Me.bindingSource1
    GetData("select * from Customers")

End Sub


C#  Copy Code
private void Form1_Load(object sender, System.EventArgs e)
{
    // Bind the DataGridView to the BindingSource
    // and load the data from the database.
    dataGridView1.DataSource = bindingSource1;
    GetData("select * from Customers");
}
Avatar billede joki Mester
24. december 2005 - 10:31 #4
Ja nu fik jeg det også til at troede bare at man skulle kalde DataBind() som når det bruges i webforms. det må vel være buzzz, som skal smide et svar men tak for hjælpen til alle.
Avatar billede Syska Mester
24. december 2005 - 13:23 #5
svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

IT-JOB

Capgemini Danmark A/S

Finance Lead (SAP)

AL Sydbank A/S (tidligere Arbejdernes Landsbank)

Afdelingschef til GDPR & Tech Regulation

Forsvarsministeriets Materiel- og Indkøbsstyrelse

IT-Sikkerhedsrådgiver til Cyberdivisionen i Hvidovre

Ringkjøbing Landbobank – Nordjyske Bank

Forretningsudvikler til procesoptimering