Oracle database table in gridview

I want to get the result of a query in my oracle database and put it in a gridview. Now my problem: I have no idea how to output it to gridview. I use gridview from the toolbar and my oracle connection works. I also have the correct query SELECT, and I can list it. I just don't know how to do this in gridview. I searched for it and I came across this: How to populate gridview using mysql? Although this does not help me.

How can I output it to gridview so that it looks exactly like a regular table in oracle database?

What should I use and how?

This is my code:

public void read()
        {
            try
            {
                var conn = new OracleConnection("")
                conn.Open();
                OracleCommand cmd = new OracleCommand("select * from t1", conn);
                OracleDataReader reader = cmd.ExecuteReader();
                DataTable dataTable = new DataTable();
            while (reader.Read())
            {
                var column1 = reader["vermogen"];
                column = (column1.ToString());
                listBox1.Items.Add(column);
            }
            conn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }
+4
2

DataTable DataGridView,

    public void read()
    {
        try
        {
            using(OracleConnection conn = new OracleConnection("....."))
            using(OracleCommand cmd = new OracleCommand("select * from t1", 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);
        }
    }
 }

OracleDataReader Load DataTable, DataGridView DataSource. , . ( , OracleConnection )

+9

DataSet:

   public void read()
   {
       try
       {
           OracleConnection conn = new OracleConnection("");
           OracleCommand cmd = new OracleCommand("select * from t1", conn);
           conn.Open();
           cmd.CommandType = CommandType.Text;
           DataSet ds = new DataSet();
           OracleDataAdapter da = new OracleDataAdapter();
           da.SelectCommand = cmd;
           da.Fill(ds);
           dataGridView1.DataSource = ds.Tables[0];

       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message);
       }
   }
}
0

All Articles