tableadapter.update 不起作用?
我有一个问题让我发疯...... 我的 PC 上有一个本地数据库 (.sdf),在互联网上有一个数据库 (MySQL),两者具有相同的结构。 我首先通过数据适配器从互联网加载数据到数据集中,然后在数据集中加载一些本地数据。
现在我想将来自互联网的数据也存储在本地数据库中,我用 Update 语句尝试了它。这必须有效,但是每次我运行程序(调试)并返回本地数据库(通过数据库资源管理器,右键单击表,显示表数据...)时,互联网数据尚未保存!
需要明确的是,我确实在我的 dataGrid1 中看到了这两个数据(来自互联网的本地数据)。
您认为问题出在哪里?
klantenTableAdapter.ClearBeforeFill = false;
DigiLocalDataSet dataset = new DigiLocalDataSet();
string MyConString = "SERVER=server;" +
"DATABASE=db;" +
"UID=uid;" +
"PASSWORD=pass;";
string sql = "SELECT klantnr, geslacht, voorletters, roepnaam, achternaam, tussenvoegsel, straat, huisnr, subhuisnr, postcode, plaats, telthuis, telmobiel, email, geboortedatum FROM klanten ORDER BY roepnaam";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand cmdSel = new MySqlCommand(sql, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
//Fill from internet
da.Fill(dataset.klanten);
//Fill from local database
klantenTableAdapter.Fill(dataset.klanten);
klantenTableAdapter.Update(dataset.klanten);
//dataset.AcceptChanges();
this.DataContext = dataset.klanten.DefaultView;
提前致谢!
I have a problem that drives me crazy...
I have a local database (.sdf) on my PC en a database on the internet (MySQL), both with same structure.
I first load data from the internet in the dataset via the dataadapter and secondly I load some local data in the dataset.
Now I want to store the data from internet also in the local database, I tried it with the Update statement. This has to work, but everytime I run the program (debug) and I went back to the local database (via the database explorer, right click on table, Show Table data...), the internet data has not been saved!
To be clear I do see both data (local en from internet) in my dataGrid1.
What do you think is the problem?
klantenTableAdapter.ClearBeforeFill = false;
DigiLocalDataSet dataset = new DigiLocalDataSet();
string MyConString = "SERVER=server;" +
"DATABASE=db;" +
"UID=uid;" +
"PASSWORD=pass;";
string sql = "SELECT klantnr, geslacht, voorletters, roepnaam, achternaam, tussenvoegsel, straat, huisnr, subhuisnr, postcode, plaats, telthuis, telmobiel, email, geboortedatum FROM klanten ORDER BY roepnaam";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand cmdSel = new MySqlCommand(sql, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
//Fill from internet
da.Fill(dataset.klanten);
//Fill from local database
klantenTableAdapter.Fill(dataset.klanten);
klantenTableAdapter.Update(dataset.klanten);
//dataset.AcceptChanges();
this.DataContext = dataset.klanten.DefaultView;
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对此很陌生,但是您是否也需要调用 SaveChanges 将其提交到数据库?
New to this, but don't you need to call SaveChanges too to commit it to the database?
看来de db引用使用了相对路径。数据集向导建议将数据库复制到您的输出目录。然而,在服务器资源管理器中,您仍在检查原始数据库。会是这样吗? ;-)
It seems that de db reference uses a relative path. The Dataset wizard proposes to copy the database to your output directory. However in the Server explorer you are still examining the original database. Could that be it? ;-)