2012-04-27 46 views
0

我試圖將數據插入數據庫,但是當我選擇插入的內容時,我得到的數據不一致。Windows Phone中的SQLite客戶端不一致的錯誤

等,我插入= 「DATA1」,B = 「DATA2」,C = 「DATA3」

但是當我選擇我獲得= 「0」,B = 「DATA2」,C =」數據3"

爲什麼我用同樣的方法,但其中一些得到不同的價值..

參考我實現:SQLiteClient for WP(我測試了它的代碼運行正確,於是我跟着他究竟是怎麼做到的,但然後我得到不同的結果..)

INSERT功能:

String t_title = txtTitle.Text; 
String t_img = "test"; 
String t_answer_a = txtAnswer1.Text; 
String t_answer_b = txtAnswer2.Text; 
String t_answer_c = txtAnswer3.Text; 
String t_answer_d = txtAnswer4.Text; 
String t_answer = txtAnswer1.Text; 
int t_cat = 1; 

int rec; 
Random rnd = new Random(); 
string strInsert = " INSERT INTO tlg_question (q_title,q_img,q_ques_a,q_ques_b,q_ques_c,q_ques_d,q_ans,q_cat) VALUES (@q_title,@q_img,@q_ques_a,@q_ques_b,@q_ques_c,@q_ques_d,@q_ans,@q_cat)"; 

tlg_question tst = new tlg_question 
{ 
    q_title = t_title, 
    q_img = t_img, 
    q_ques_a = t_answer_a, 
    q_ques_b = t_answer_b, 
    q_ques_c = t_answer_c, 
    q_ques_d = t_answer_d, 
    q_ans = t_answer, 
    q_cat = t_cat 
}; 
rec = (Application.Current as App).db.Insert<tlg_question>(tst, strInsert); 

選擇功能:

ObservableCollection<tlg_question> _tlg_questionEntries = null; 

string strSelect = "SELECT q_id,q_title,q_img,q_ques_a,q_ques_b,q_ques_c,q_ques_d,q_ans,q_cat FROM tlg_question ORDER BY q_id DESC LIMIT 0,1"; 
_tlg_questionEntries = (Application.Current as App).db.SelectObservableCollection<tlg_question>(strSelect); 

foreach (tlg_question data in _tlg_questionEntries) 
{ 
    qid = data.q_id; 
    txtTitle.Text += data.q_title; 
    img = data.q_img; 
    txtAnswer1.Text += data.q_ques_a; 
    txtAnswer2.Text += data.q_ques_b; 
    txtAnswer3.Text += data.q_ques_c; 
    txtAnswer4.Text += data.q_ques_d; 
} 

而且我的更新功能:

String t_title = txtTitle.Text; 
String t_answer_a = txtAnswer1.Text; 
String t_answer_b = txtAnswer2.Text; 
String t_answer_c = txtAnswer3.Text; 
String t_answer_d = txtAnswer4.Text; 

int rec; 
Random rnd = new Random(); 
string strUpdate = " UPDATE tlg_question SET [email protected]_title,[email protected]_ques_a,[email protected]_ques_b,[email protected]_ques_c,[email protected]_ques_d,[email protected]_ans WHERE [email protected]_id"; 

tlg_question tst = new tlg_question 
{ 
    q_id = qid, 
    q_title = t_title, 
    q_ques_a = t_answer_a, 
    q_ques_b = t_answer_b, 
    q_ques_c = t_answer_c, 
    q_ques_d = t_answer_d, 
    q_ans = t_answer_a 
}; 
rec = (Application.Current as App).db.Update<tlg_question>(tst, strUpdate); 

欣賞人誰可以幫我!

*或者,如果你認爲我應該放棄SQLite和去其他數據庫,請讓我知道,我在挑首位SQLite的,因爲它處理,如MySQL簡單的查詢,以及FF SQLite的經理..

謝謝!

回答

0

好吧,我已經測試過,最後發現,我需要同時插入或更新所有列,然後只有我可以正確完成工作,我不確定這是因爲DBHelper限制發生的還是來自SQLiteClient。

進一步瞭解詳細:

例如,如果我的預置數據庫宣佈4列如下:

[q_id, q_title, q_ques, q_ans] (q_id as Auto Increment) 

然後當我在做INSERT或UPDATE,甚至我只需要插入只有q_title(而離開q_ques和q_ans使用默認值),我將需要包括所有列的運行參數:

INSERT INTO tlg_question (q_title,q_ques,q_ans) VALUES (@q_title,@q_ques,@q_ans)"; 

不喜歡我做的,通常在PHP MYSQL,我可以簡單地插入/更新特定的專欄中,我想沒有問題:

INSERT INTO tlg_question (q_title) VALUES (@q_title)"; 

P/S:我在SQLite和C#新的,請指教/糾正我,如果你知道什麼是實際發生的事情..

謝謝! :)

相關問題