Click here to Skip to main content
13,147,919 members (33,850 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have following code with table customer having id and name field .......when i insert new record i want to change datagrid simultaneously
so i performed this but on load() i am getting blank data grid view

 private void load()
            string sql = "select * from customer";
            SqlDataAdapter myAdapter = new SqlDataAdapter(sql, con);
            DataSet myDataSet = new DataSet("customer");
            dataGridView1.DataSource = myDataSet;
private void button4_Click(object sender, EventArgs e)
           if (txtname.Text != "" & txtage.Text != "")
               com.CommandText = "insert into customer(customerName,customerCode) values ('" + txtname.Text + "','" + txtage.Text + "')";
               MessageBox.Show("record inserted");
           else MessageBox.Show("data entry error");

here button will add record ....................record is getting insert but datagrid view on load function gibes blank
plz tell wat i have missed

Posted 8-Jan-13 19:25pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

datagrid view on load function gibes blank
You point to dataset instead of table to grid. Try:
DataTable myDataTable = new DataTable("customer");
dataGridView1.DataSource = myDataTable;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100