你好大家 我的框架: - Microsofr window7 - Visual Studio 2008 我使用的是AdventureWorks我的应用程序的数据库示例。 我创建的窗口表单应用程序包括: - 1 datagridview:name = datagridview1 - 1按钮:name = button1 我用visual studio 2008的工具添加数据源(数据>添加新数据源......) 我只选择了AWBuildVersion表(在AdventureWorks数据库中) 现在我有: - AdventureWorks_DataDataSet 我的目的是按'button1'将创建新的AWBuildVersionRow,它显示到datagridview1然后保存到AdventureWorks数据库永久 我的代码:
hello everyone My framework: - Microsofr window7 - Visual studio 2008 I used AdventureWorks database sample for my application. I created window form application include: - 1 datagridview: name = datagridview1 - 1 button: name=button1 I used visual studio 2008's tool to add Datasource (Data>Add new data source...) I only selected AWBuildVersion table (which within AdventureWorks database) Now I had: - AdventureWorks_DataDataSet My purpose is press 'button1' will create new AWBuildVersionRow, it was display to datagridview1 and then save it to AdventureWorks database permanently My code:
byte i = 1; private void button1_Click(object sender, EventArgs e) { AdventureWorks_DataDataSetTableAdapters.AWBuildVersionTableAdapter da = new WindowsFormsApplication2.AdventureWorks_DataDataSetTableAdapters.AWBuildVersionTableAdapte(); AdventureWorks_DataDataSet.AWBuildVersionDataTable table = da.GetData(); AdventureWorks_DataDataSet.AWBuildVersionRow row = table.NewAWBuildVersionRow(); row.BeginEdit(); row.Database_Version = "version"; row.SystemInformationID = ++i; row.VersionDate = DateTime.Now; row.ModifiedDate = DateTime.Now; row.EndEdit(); table.AddAWBuildVersionRow(row); da.Update(table); //save changes to database this.aWBuildVersionTableAdapter.Fill(this.adventureWorks_DataDataSet.AWBuildVersion); }我跑了DEBUG。结果是: 当我按'button1'时。 datagridview1上显示了新行。然后停止DEBUG 片刻之后,我运行DEBUG。上面创建的新行仍然显示。 但是如果我停止DEBUG。很长一段时间后我运行DEBUG,上面创建的新行没有显示。 我不明白为什么会这样。 请帮助我!非常感谢
I ran DEBUG. The result is: when I press 'button1'. New row was displayed on datagridview1. Then stop DEBUG A moment later, I run DEBUG. Above created new row still was displayed. But if I stop DEBUG. And a long time later I run DEBUG, Above created new row was not displayed. I can't understand why is that. please help me! thank you very much
推荐答案更新数据库中的ds,你需要设置CommandBuilder并设置InsertCommand,UpdateCommand或DeleteCommand。 pl 。检查以下链接 support.microsoft/kb/308507 for update the ds in database you need to set CommandBuilder and set InsertCommand, UpdateCommand, or DeleteCommand . pl. check below link support.microsoft/kb/308507
在DataSource配置向导中,您是否可以选中此复选框启用本地数据库缓存并且在插入之前,开发环境以某种方式保留了数据的缓存副本?然后在它重新加载缓存的数据?我已经尝试过你的代码了,它肯定正确写入SQL Server,然后更新DataGridView ...... Is it possible that during the DataSource Configuration Wizard that you checked the box "Enable local database caching" and somehow the development environment is retaining a cached copy of the data before your insert? Then later on it reloads that cached data? I've tried your code and it is certainly writing to SQL Server correctly, then updating the DataGridView...
更多推荐
无法永久保存对sql server 2008的更改
发布评论