Sunday, July 8, 2012

Read all the Records in a Database to a GridView



 private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection();

            SqlDataAdapter dataAdapter;
            DataSet dataSet;
            connection.ConnectionString = Trial.Program.Globals.db.connectionString;

            connection.Open();

            dataAdapter = new SqlDataAdapter("select * from Item", connection);

            dataSet = new DataSet();
            DataTable t = new DataTable();

            dataAdapter.Fill(t);
            dgvAllItems.DataSource = t;

            connection.Close();  }

No comments:

Post a Comment