【发布时间】:2014-02-03 14:01:57
【问题描述】:
我在两个日期之间检索数据,一些如何获得正确的结果,一些如何在我选择带有月份的日期时输出空列表视图,但当我选择超过一个月的日期时,它输出空列表视图下面是我的代码
这里我在 DB 类中声明变量
public static final String EX_RowID = "_id";
public static final String EX_Cattype = "Ecattype";
public static final String EX_Date = "Ecdate";
public static final String EX_Price = "Ecprice";
public static final String EX_Type = "itype";
建表语句
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + Food_TABLE +"(" +
EX_RowID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
EX_Cattype + " TEXT NOT NULL, " +
EX_Date + " TEXT NOT NULL," +
EX_Price + " INTEGER NOT NULL," +
EX_Type + " TEXT NOT NULL UNIQUE );"
);
}
输入数据方法
public long ExEntry(String Ecatgtype, String Edate, String Eprice, String Eitype) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(EX_Cattype, Ecatgtype);
cv.put(EX_Date, Edate );
cv.put(EX_Price, Eprice);
cv.put(EX_Type, Eitype);
return ourdatabase.insertOrThrow(Food_TABLE, null, cv);
}
这里我访问 ExEntry 方法
ExMgDB Expentry = new ExMgDB(ADD_EX.this);
Expentry.open();
Expentry.ExEntry(cate, date, price, itype);
Expentry.close();
这里我面临这两个日期变量之间的问题
public Cursor CstmRpot(String fd, String td) {
// TODO Auto-generated method stub
String[] columns = new String[] {EX_RowID,EX_Cattype, EX_Date, EX_Price, EX_Type };
Cursor c= ourdatabase.query(Food_TABLE, columns, EX_Date + " BETWEEN '" + fd + "'
AND '" + td + "'" , null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
我像下面这样访问它
CustemRpt dbcs = new CustemRpt();
Cursor cursor = CstDB.CstmRpot(frmdate,tondate);
【问题讨论】:
-
您如何在 Ecdate 字段中存储日期值?如果您使用字符串字段来存储日期,请确保作为字符串的排序对于相应的日期也有效。为此,您应该将日期存储为 yyyymmdd
-
所以当我改变甲酸盐时,你认为这是正确的结果
-
订购是什么意思
-
要获取两个日期之间的数据范围,数据库引擎需要获取有序列表,不是吗?
-
我做了你的方法,但问题存在