Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i am working on datagrid these day.
i created a datagrid and add some column in it. after that i create a table in mssql and assign some column there also.
now what i want is whenever i insert some value in my textboxes and click my button,it will get entered in the database and at the same time shown in the datagrid columns.
i already entered data in the db table but unable to enter values in datagrid.
can anybody help me
neaS
Posted

After inserting a record you have write query for fetching the data from table and bind the datagrid.
Check this article.

http://www.dotnetperls.com/datagridview-tutorial[^]
 
Share this answer
 
After you inserting data into database then rebind the datagrid with database.

Thanks,
Mamun
 
Share this answer
 
you can use this.
C#
privte void on Form1_load(Object sender , EventArgs e)
        {
            DataSet ds = new DataSet();
            string str = "select * from user1 ";
            
            adap = new SqlDataAdapter(str, con);
            adap.Fill(ds, "user1");
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ds.Tables["user1"];
            dataGridView1.Columns["FirstName"].DataPropertyName = "FirstName";
            dataGridView1.Columns["LastName"].DataPropertyName = "LastName";
            dataGridView1.Columns["username"].DataPropertyName = "username";
            dataGridView1.Columns["password"].DataPropertyName = "password";
         }
 
Share this answer
 
Hi,

you can use
C#
datagridview1.rows.add(textbox1.text, textbox2.text, textbox3.text);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900