使用VARCHAR时,您可能还需要指定长度,或者通常最好这样做
那么抓取文本,将其制作成字符串,然后将其放入查询中怎么样?
String TableName = "ComplicatedTableNameHere";
EditText editText1 = (EditText) findViewById(R.id.EditTextIDhere);
String editTextString1 = editText1.getText().toString();
崩溃了
String TableName = "ComplicatedTableNameHere";
//sets the table name as a string so you can refer to TableName instead of writing out your table name everytime
EditText editText1 = (EditText) findViewById(R.id.EditTextIDhere);
//gets the text from your edit text fieldfield
//editText1 = your edit text name
//EditTextIDhere = the id of your text field
String editTextString1 = editText1.getText().toString();
//sets the edit text as a string
//editText1 is the name of the Edit text from the (EditText) we defined above
//editTextString1 = the string name you will refer to in future
然后使用
myDB.execSQL("INSERT INTO "
+ TableName
+ " (Column_Name, Column_Name2, Column_Name3, Column_Name4)"
+ " VALUES ( "+EditTextString1+", 'Column_Value2','Column_Value3','Column_Value4');");
希望这能在某种程度上有所帮助...
注意:每个字符串都在
中。
'"+stringname+"'
是 'and' 使字符串的多行元素生效,没有它,你只能得到第一行,甚至不确定是否得到整行,可能只有第一个单词。