c# - MySqlDataAdapter使用Update以后在使用Fill填充Table時(shí)得不到數(shù)據(jù)
問(wèn)題描述
在wpf中從數(shù)據(jù)庫(kù)讀取到的數(shù)據(jù)binding到DataGrid,然后將修改后的DataTable更新到數(shù)據(jù)庫(kù)中第一次select查詢以及綁定沒(méi)有問(wèn)題,updateDataTable到數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)中的數(shù)據(jù)被更新,然后再次使用select的時(shí)候就再也查詢不到數(shù)據(jù),重新聲明這個(gè)類都沒(méi)有效果,除非重啟軟件,請(qǐng)問(wèn)是那里出的問(wèn)題,代碼如下:
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ù)過(guò)程:
IDbMysql db = new IDbMysql();DataTable dt = db.select('select * from tableA');// 這里是對(duì)dt的修改,省略一些代碼db.updateDataTable(dt); // 這里執(zhí)行都是成功的,數(shù)據(jù)庫(kù)也修改了DataTable dtNew = db.select('select * from tableA'); // 這里就查詢不到數(shù)據(jù)了,然會(huì)0條數(shù)據(jù),但是數(shù)據(jù)庫(kù)里面是可以看到數(shù)據(jù)的
問(wèn)題解答
回答1:碰到同樣的問(wèn)題,求助怎么解決的
相關(guān)文章:
1. javascript - sublime快鍵鍵問(wèn)題2. javascript - immutable配合react提升性能?3. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽(tīng)數(shù)據(jù)變化4. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語(yǔ)法錯(cuò)誤5. css - 寫頁(yè)面遇到個(gè)布局問(wèn)題,求大佬們幫解答,在線等,急!~6. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問(wèn)7. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?8. phpstudy8.1支持win11系統(tǒng)嗎?9. 實(shí)現(xiàn)bing搜索工具urlAPI提交10. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問(wèn)?

網(wǎng)公網(wǎng)安備