在DataGridView中显示自动递增的列值(Identity Feature) [英] Displaying auto incremented column values(Identity Feature) in DataGridView

查看:122
本文介绍了在DataGridView中显示自动递增的列值(Identity Feature)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Sql Server 2008中有一个表,我在使用Identity功能在添加新行时自动递增值。我想在DataGridView上显示整列自动递增值。



以下是我用来填充GridView的代码



I have a table in Sql Server 2008 where I am using Identity feature to auto increment values as soon as a new row is added.I want to display the entire column of auto incremented values on a DataGridView.

Following is my code that I am using to populate the GridView

public void LoadOnlyLeadMasters()
        {
            try
            {
                DS_Main.Tables["LeadMasters"].Clear();
                string query = "SELECT * FROM LeadMasters";
                cmd = new OleDbCommand(query, con);
                cmd.ExecuteNonQuery();
                adp = new OleDbDataAdapter(query, con);
                adp.Fill(DS_Main, "LeadMasters");
            }
            catch (Exception E)
            {
                ErrorLog(E);
            }
        }

 public void DisplayingGridView()
        {
             Mainform = new Form1(Login);
             Mainform.LoadOnlyLeadMasters();
             Display_dataGridView1.DataSource = Form1.DS_Main.Tables["LeadMasters"];
            //Display_dataGridView1.DataMember = "LeadMasters";

            for (int i = 0; i < Display_dataGridView1.Columns.Count; i++)
            {
                Display_dataGridView1.Columns[i].Visible = false;
            }


            Display_dataGridView1.Columns["CompanyName"].Visible = true;
            Display_dataGridView1.Columns["PersonName"].Visible = true;
            Display_dataGridView1.Columns["Number"].Visible = true;
            Display_dataGridView1.Columns["Emailaddress"].Visible = true;
            Display_dataGridView1.Columns["Product"].Visible = true;
            Display_dataGridView1.Refresh();
        }





我希望我已经提供了足够的有关该问题的信息。如果没有让我知道



谢谢



I hope I have provided enough information about the issue.If not do let me know

Thanks

推荐答案

网格视图中有一些事件你可以使用以下相同的链接



GridView all in one [ ^ ]





在ASP.NET中编辑单个GridView单元格 [ ^ ]





使用GridView事件处理RowCommand并使用jQuery [ ^ ]
There are some events of grid view you can use for the same following are links

GridView all in one[^]


Edit Individual GridView Cells in ASP.NET[^]


Handling GridView events using RowCommand and using jQuery[^]


这篇关于在DataGridView中显示自动递增的列值(Identity Feature)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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