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. html - radio的使用時(shí)如何避免整個(gè)頁面只能選一個(gè)的情況2. git - webstorm窗口中左側(cè)列表的文件名顏色怎么修改3. javascript - 最近用echarts做統(tǒng)計(jì)圖時(shí)遇到兩個(gè)問題!!4. javascript - 深夜被問題困擾求解惑,rn的API之PermissionsAndroidd的問題5. 前端 - html5 audio不能播放6. docker綁定了nginx端口 外部訪問不到7. 如何解決docker宿主機(jī)無法訪問容器中的服務(wù)?8. java - Activity 進(jìn)入后臺(tái)再次傳值?9. 利用百度地圖API定位及附件商家信息服務(wù)10. javascript - RN項(xiàng)目iOS端真機(jī)測(cè)試賬號(hào)無法登錄!

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