简体   繁体   English

在向DB表中添加更多列时,如何让datagridview显示更改?

[英]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. 我在visual studio中的项目中创建了一个数据集,该数据集指向我的数据库中的表,然后将datagridview控件绑定到它。

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. 然后我想更新datagridview,但我无法添加新列。 I can right click on the tableadapter in the form where the datagridview is and get the correct table data up. 我可以在datagridview所在的表单中右键单击tableadapter并获取正确的表数据。

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. 如果我从表单中删除tableadapter和bindingsource和dataset实例,然后尝试重新绑定它,无关紧要,datagridview仍然不会让我添加新列。

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. 我已经尝试了几个项目,包括VS2008和2010 beta,而不是其他语言而不是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. 请执行以下步骤:1。转到数据集并添加新列2.转到数据绑定源并修改查询。 3. Go to the datagridview and add the new column 3.转到datagridview并添加新列

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 如果将GridView AutoGeneratedColumn属性设置为tru,它将自动反映该列,但如果将其设置为fasle,则必须在<Columns> Tag之间在aspx页面中添加标记

<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" “C:\\用户\\ YOURUSERNAME \\应用程序数据\\本地\\微软\\ VisualStudio的\\ 9.0 \\ ProjectAssemblies”
visual studio has a load of compiled things it uses for quick reference. visual studio有一堆用于快速参考的编译物。 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) 1.我们首先关闭Visual Studio(我只是为了安全起见)
2. Delete all the folders in the ProjectAssemblies folder. 2.删除ProjectAssemblies文件夹中的所有文件夹。
3. Open up Visual Studio again 3.再次打开Visual Studio
4. Rebuild solution 4.重建解决方案
5. And NOW we get the correct values when we add columns to our datagridview. 5.现在,当我们向datagridview添加列时,我们会得到正确的值。

WHEW! 呼! :D :d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使数据显示在正确的DataGridView列中? - How do I get my data to show in correct DataGridView column? 如何在c#的datagridview列中防止两个以上的小数位? - How do you prevent more than two decimal places in datagridview column in c#? 单击列时如何更改DataGridView的行为? - How to change the behavior of the DataGridView when clicking a column? 如何在Datagridview C#中显示更多表 - How I Can Show More Table In Datagridview C# 当您有 integer 列 (CategoryID) 和 combobox 中的文本时,如何通过 combobox 将数据插入 datagridview? - how do I insert data into a datagridview via combobox when you have an integer column (CategoryID) and text in the combobox? 如何将更多单元格添加到datagridview列? - How do i add more cells to a column of datagridview? 如何更改列值以在绑定DataGridView中显示不同的值? - How to change column values to show different value in bind DataGridView? 如何在导入到dataGridView的表中使标题行不可选择 - How do you make the header row unselectable in a table that was imported into a dataGridView LinqToSql:当您还不知道数据库表时,如何读取数据? - LinqToSql: How do you read data when you don't know the DB Table yet? 将按钮列添加到DataGridView但不会显示 - Adding button column to DataGridView but it won't show
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM