![]() |
||
|
Major Member
![]() 加入日期: Apr 2001 您的住址: 台北.台灣
文章: 156
|
請c#高手幫忙一下@@ 想一天了!! 無解
在2010 VC# 底下
============================================== mysql mydb [coid (key)] [cowhere] [comoney] [coincome] [comons] [coday conote] ============================================== private void button3_Click(object sender, EventArgs e) { int coid = Int32.Parse(nmbBox2.Text); string cowhere = wh2Box4.Text; string comoney = moneyBox5.Text; string conote = noteBox6.Text; string connStr = "server=localhost;user=root;database=mydb;port=3306;password=;Charset=utf8"; MySqlConnection conn = new MySqlConnection(connStr); conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "updata expenses set cowhere=@cowhere,comoney=@comoney , conote=@conote where coid=@coid "; cmd.Prepare(); cmd.Parameters.AddWithValue("@cowhere", cowhere); cmd.Parameters.AddWithValue("@comoney", comoney); cmd.Parameters.AddWithValue("@conote", conote); cmd.ExecuteNonQuery(); 每次都會說錯誤!! 實在無解!! conn.Close(); button1_Click(this, e);
__________________
不知道為什麼來,沒有留下什麼..卻只帶走一些遺憾! 投資等於賭博?? |
|||||||
|
|
|
New Member
加入日期: Jul 2011
文章: 3
|
引用:
UPDATE 不是 UPDATA ,另求救請將錯誤訊息列出來。 寫程式,最好學會 DEBUG ,別光靠看程式碼抓蟲。 此文章於 2011-10-23 10:13 PM 被 roger214 編輯. |
|||
|
|
|
Major Member
![]() 加入日期: Apr 2001 您的住址: 台北.台灣
文章: 156
|
roger214大大
原來我是豬頭~update一直沒發現= =" 後來我改成update了!編譯成功! 按下button ~還是會跑出錯誤~~ Mysql.Data.MysqlClient.MysqlException {"Fatal error encountered during command execution."} ![]()
__________________
不知道為什麼來,沒有留下什麼..卻只帶走一些遺憾! 投資等於賭博?? |
|
|
|
Major Member
![]() 加入日期: Apr 2001 您的住址: 台北.台灣
文章: 156
|
我也希望自己做DeBug 的if!!
但是 功力不強!不知道 cmd.ExecuteNonQuery(); 到底要怎麼下手!! if (cmd.ExecuteNonQuery() ![]() Console.WriteLine("\t{0}\t{1}", rdr.GetInt32(0), rdr.GetString(1)); else Console.WriteLine("No rows returned."); ....囧!!!
__________________
不知道為什麼來,沒有留下什麼..卻只帶走一些遺憾! 投資等於賭博?? |
|
|
|
New Member
加入日期: Jul 2011
文章: 3
|
引用:
嗯 UPDATE 語法去查一下,你 SQL 應該很不熟悉吧?你試試 SET 之後加個 WHERE 1 看看。 另外,cowhere、comoney、conote 必須至少有一筆資料存在,只建好 schema 是不夠的,update 必須在資料表中已有資料,才能進行更新。 |
|
|
|
|
*停權中*
加入日期: Nov 2010 您的住址: 猩燭
文章: 274
|
你先確定SQL字串在sql express查詢確定是Ok的後
再設中斷點,執行觸發後,按F10或F11單步debug, 這很簡單吧...連vs 2010好用的debug都不會就完了 ![]() 還有,你要先確定你的connection到底有沒有成功... 用try catch來抓就知道了code如果看不出來哪裡有問題,只好開始慢慢debug... ![]() 此文章於 2011-10-23 10:23 PM 被 Jens Rydén 編輯. |
|
|
|
Major Member
![]() 加入日期: Aug 2001
文章: 211
|
你有幫 mysql 的 root 設 password 嗎?
__________________
滿招損 謙受益 |
|
|
|
New Member
加入日期: Jul 2011
文章: 3
|
引用:
Virtual Studio 就有除錯器了,你可以在執行之前設好中斷點,執行後從中斷點單步執行,觀察你要檢查的程式碼以及變數。 |
|
|
|
|
Silent Member
加入日期: Oct 2010
文章: 0
|
引用:
「coid」參數值忘了放進去吧? |
|
|
|
|
Major Member
![]() 加入日期: Apr 2001 您的住址: 台北.台灣
文章: 156
|
引用:
darkangel 沒有耶@@ 因為我實作insert的button 沒設密碼也可以pass ^^ 所以就沒設mysql密碼了@@
__________________
不知道為什麼來,沒有留下什麼..卻只帶走一些遺憾! 投資等於賭博?? |
|
|
|