Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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
Posted
Comments
[no name] 1-Jan-15 0:44am    
Is it not coming the values???
Vivek Murli 1-Jan-15 0:58am    
Yeah the auto incremented column values
[no name] 1-Jan-15 1:25am    
Is it also the primary key??
George Jonsson 1-Jan-15 1:13am    
What is the name of the identity column?
First you make all columns invisible and then make some columns visible.
It doesn't make sense if you want to show the identity column.

1 solution

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[^]
 
Share this answer
 
Comments
Thanks7872 1-Jan-15 2:23am    
OP states that Autoincrement columns are not getting displayed at UI(DataGridView) and you posted 3 links explaining how to work with Gridview. How this can help OP? Saying someone 'Read this Article' before understanding the issue won't help anyone.

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