简体   繁体   中英

when adding a column more to a DB table, how do you get your datagridview to show the change?

I have created a dataset in a project in visual studio that points to a table in my database and then bound a datagridview control to it.

Now I open the database and add another column to the table in the database. Then i open the dataset and update it's configuration to include the change.

Then i want to update the datagridview, but I can't add the new column. I can right click on the tableadapter in the form where the datagridview is and get the correct table data up.

It does not matter if I delete the tableadapter and the bindingsource and dataset instance from the form, and then try and rebind it, the datagridview still won't let me add the new column.

Does anyone have an idea what is happening?
I've tried this with several projects, both VS2008 and 2010 beta, not with other languages than C# tho.
The only solution so far seems to be to make a whole different dataset, but there has to be a better way.

Thanks in advance

Follow the following steps: 1. Go to dataset and add the new column 2. Go to the databindingsource and modify the query. 3. Go to the datagridview and add the new column

I simulated the same scenario as told by you and it worked.

If you set the GridView AutoGeneratedColumn property to tru it will auto reflect the column, but if you set it to fasle you have to add the markup in aspx page like this between <Columns> Tag

<asp:BoundField DataField="ColumnName" HeaderText="Header Text which you want to for table th " />

I hope this will work for you.

Thanks

Under the folder in
"C:\\Users\\YOURUSERNAME\\AppData\\Local\\Microsoft\\VisualStudio\\9.0\\ProjectAssemblies"
visual studio has a load of compiled things it uses for quick reference. These are named after some hashing scheme so we can't tell which one is the compiled settings for our botched table scheme.
1. We start by closing Visual Studio (I just did it to be on the safe side)
2. Delete all the folders in the ProjectAssemblies folder.
3. Open up Visual Studio again
4. Rebuild solution
5. And NOW we get the correct values when we add columns to our datagridview.

WHEW! :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM