如何填充数据网格 [英] how to populate datagrid

查看:90
本文介绍了如何填充数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我今天正在研究datagrid.
我创建了一个数据网格,并在其中添加了一些列.之后,我在mssql中创建了一个表,并在那里也分配了一些列.
现在我想要的是每当我在文本框中插入一些值并单击我的按钮时,它将被输入到数据库中,并同时显示在datagrid列中.
我已经在db表中输入了数据,但是无法在datagrid中输入值.
有人可以帮我吗
neaS

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

推荐答案

插入记录后,您将编写查询以从表中获取数据并绑定datagrid.
查看本文.

http://www.dotnetperls.com/datagridview-tutorial [
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[^]


将数据插入数据库后,将datagrid与数据库重新绑定. br/>
谢谢,
Mamun
After you inserting data into database then rebind the datagrid with database.

Thanks,
Mamun


您可以使用它.
you can use this.
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";
         }


这篇关于如何填充数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆