0

I have a datagridview in my Windows C# application. I am binding some data from my SQL server 2005 database into it. The datagridview already has a fixed number of columns and rows with their indivdual names. The problem is the data is displayed after the columns where i wish to get my data. The code is as following

SqlCommand cmd = new SqlCommand("Select * from INV_details_1 where i_n = '" + textBox3.Text + "'", sconn);

            SqlDataAdapter da2 = new SqlDataAdapter();

            da2.SelectCommand = cmd;

            DataSet ds2 = new DataSet();

           da2.Fill(ds2);

            dgv_details.DataSource = ds2.Tables[0].DefaultView;

The issue is that the data is getting displayed after my desired column headers. I wish to get the data in these specified columns.

Please help

1 Answer 1

1

You must map each column of the datagridview with the corresponding column in database using DataPropertyName property of Datagridview's column. EX:

dgv_details.Columns[0].DataPropertyName = "Name"

This will map column 0 in datagridview with column "Name" in datatable

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.