简体   繁体   中英

How to get all data from database into datagridview?

I want to display some data inside a DataGridview from Oracle server, but I only get the headers of the columns.

It's an old Oracle server (maybe 7 or 9). In SQL developer I see the data.

I tried this:

OracleConnection conn = new OracleConnection(oradb);
conn.Open();            
adpt = new OracleDataAdapter("select * from teszt;", conn);
dt = new DataTable();
adpt.Fill(dt);
dataGridView1.DataSource = dt;

Thanks for the help.

Replace your code to this one..

public void BindGridView()
{
    try
    {
        using(OracleConnection conn = new OracleConnection("add your connection details"))
        using(OracleCommand cmd = new OracleCommand("select * from teszt", conn))
        {
            conn.Open();
            using(OracleDataReader reader = cmd.ExecuteReader())
            {
                DataTable dataTable = new DataTable();
                dataTable.Load(reader);
                dataGridView1.DataSource = dataTable;
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM