views:

7

answers:

0

Hi GUys,

I want to fill my DataGridView from database using ODBC connection. How can I achieve this?

        string userName = ConfigurationSettings.AppSettings["userName"];
        string password = ConfigurationSettings.AppSettings["password"];
        string connectionString = userName + password;

        OdbcConnection odbcConnection = new OdbcConnection(connectionString);
        odbcConnection.Open();

        string query = "select * from printjob";
        OdbcCommand cmd = new OdbcCommand();
        cmd.Connection = odbcConnection;
        cmd.CommandText = query;

        OdbcDataReader reader = cmd.ExecuteReader();
        //OdbcDataAdapter adapter = new OdbcDataAdapter(query, connectionString);
        //DataSet ds = new DataSet();
        //adapter.Fill(ds);
        //DataTable table = new DataTable();

        //while (reader.HasRows)
        //{
        //    table.Columns.Add(reader.GetString(0));
        //    table.Columns.Add(reader.GetString(1));
        //}

        //DataSet ds = new DataSet();
        //ds.Tables.Add(table);

        //dataGridView1.DataSource = reader;
        //dataGridView1.DataBindings = 
        //dataGridView1.Show();
        odbcConnection.Close();