c# - MySqlDataAdapter使用Update以后在使用Fill填充Table時(shí)得不到數(shù)據(jù)
問題描述
在wpf中從數(shù)據(jù)庫讀取到的數(shù)據(jù)binding到DataGrid,然后將修改后的DataTable更新到數(shù)據(jù)庫中第一次select查詢以及綁定沒有問題,updateDataTable到數(shù)據(jù)庫,數(shù)據(jù)庫中的數(shù)據(jù)被更新,然后再次使用select的時(shí)候就再也查詢不到數(shù)據(jù),重新聲明這個(gè)類都沒有效果,除非重啟軟件,請(qǐng)問是那里出的問題,代碼如下:
public class IDbMysql{ MySqlConnection db_conn; public IDbMysql(string ip, int port, string userName, string userPwd, string database) {string str_db_conn = string.Format('Server={0};Port={1};Database={2};Username={3};Password={4};charset=utf8;', ip, port, database, userName, userPwd);db_conn = new MySqlConnection(str_db_conn);db_conn.Open(); } public DataTable select(string db_string) {DataTable dt = new DataTable();MySqlDataAdapter adapter = new MySqlDataAdapter(db_string, db_conn);adapter.Fill(dt);return dt; } public int updateDataTable(string db_string, DataTable db_datatable) {int ret = -1;MySqlDataAdapter adapter = new MySqlDataAdapter(db_string, db_conn);MySqlCommandBuilder builder = new MySqlCommandBuilder(adapter);ret = adapter.Update(db_datatable);return ret; }}
調(diào)用函數(shù)過程:
IDbMysql db = new IDbMysql();DataTable dt = db.select('select * from tableA');// 這里是對(duì)dt的修改,省略一些代碼db.updateDataTable(dt); // 這里執(zhí)行都是成功的,數(shù)據(jù)庫也修改了DataTable dtNew = db.select('select * from tableA'); // 這里就查詢不到數(shù)據(jù)了,然會(huì)0條數(shù)據(jù),但是數(shù)據(jù)庫里面是可以看到數(shù)據(jù)的
問題解答
回答1:碰到同樣的問題,求助怎么解決的
相關(guān)文章:
1. angular.js - 輸入郵箱地址之后, 如何使其自動(dòng)在末尾添加分號(hào)?2. 管理員信息修改時(shí)的密碼問題3. javascript - JS 里面的 delete object.key 到底刪除了什么?4. android - RxJava 中有根據(jù)條件執(zhí)行不同函數(shù)的操作符嗎?5. mysql - 電商如何存儲(chǔ)營(yíng)業(yè)額數(shù)據(jù)6. javascript - 后臺(tái)管理系統(tǒng)左側(cè)折疊導(dǎo)航欄數(shù)據(jù)較多,怎么樣直接通過搜索去定位到具體某一個(gè)菜單項(xiàng)位置,并展開當(dāng)前菜單7. javascript - html5的data屬性怎么指定一個(gè)function函數(shù)呢?8. javascript - 如何使用nodejs 將.html 文件轉(zhuǎn)化成canvas9. html5 - 為什么使使用vue cli 腳手架,post-css 沒有自動(dòng)對(duì)css3屬性自動(dòng)添加瀏覽器前綴呢?10. java如何生成token?
