c# - MySqlDataAdapter使用Update以后在使用Fill填充Table時得不到數(shù)據(jù)
問題描述
在wpf中從數(shù)據(jù)庫讀取到的數(shù)據(jù)binding到DataGrid,然后將修改后的DataTable更新到數(shù)據(jù)庫中第一次select查詢以及綁定沒有問題,updateDataTable到數(shù)據(jù)庫,數(shù)據(jù)庫中的數(shù)據(jù)被更新,然后再次使用select的時候就再也查詢不到數(shù)據(jù),重新聲明這個類都沒有效果,除非重啟軟件,請問是那里出的問題,代碼如下:
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');// 這里是對dt的修改,省略一些代碼db.updateDataTable(dt); // 這里執(zhí)行都是成功的,數(shù)據(jù)庫也修改了DataTable dtNew = db.select('select * from tableA'); // 這里就查詢不到數(shù)據(jù)了,然會0條數(shù)據(jù),但是數(shù)據(jù)庫里面是可以看到數(shù)據(jù)的
問題解答
回答1:碰到同樣的問題,求助怎么解決的
相關(guān)文章:
1. javascript - 關(guān)于apply()與call()的問題2. javascript - 有適合開發(fā)手機(jī)端Html5網(wǎng)頁小游戲的前端框架嗎?3. python - pandas按照列A和列B分組,將列C求平均數(shù),怎樣才能生成一個列A,B,C的dataframe4. python - Pycharm的Debug用不了5. html - eclipse 標(biāo)簽錯誤6. python 利用subprocess庫調(diào)用mplayer時發(fā)生錯誤7. javascript - nginx反向代理靜態(tài)資源403錯誤?8. python文檔怎么查看?9. python - pycharm 自動刪除行尾空格10. 安全性測試 - nodejs中如何防m(xù)ySQL注入
