我试图将数据插入数据库,但是当我选择我插入的内容时,我得到不一致的数据。
比如,我插入 a="data1", b="data2", c="data3"
但是当我选择时,我得到 a="0", b="data2", c="data3"
为什么我使用相同的方法,但其中一些获得不同的价值..
我的工具参考:SQLiteClient for WP(我测试了他的代码,它运行正确,我完全按照他的做法,但是我得到了不同的结果..)
插入功能:
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 q_title=@q_title,q_ques_a=@q_ques_a,q_ques_b=@q_ques_b,q_ques_c=@q_ques_c,q_ques_d=@q_ques_d,q_ans=@q_ans WHERE q_id=@q_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 Manager..
谢谢!