我必须从表中获取所有记录。我的方法如下:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'Column 7 is the one to which is the code is applied
ElseIf Target.Column = 7 Then
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
Else
If newVal = "" Then
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
目前它正在归还我0.我的日期格式是" yyyy-MM-dd HH:mm:ss"
请指导我在哪里做错了。谢谢!
答案 0 :(得分:1)
或现有代码只需致电cursor.getCount();
total=cursor.getCount();
Cursor.getCount();
返回游标中的行数。
<强>已更新强>
查询以获取两个日期SO - How to select data between two date range in android SQLite
查询是
SELECT * FROM mytab where my_date BETWEEN '2016-03-01 00:00:00' AND '2016-03-19 00:00:00'
答案 1 :(得分:0)
我认为你应该使用COUNT(*)而不是*。
试试这个。
public int getTasksByStatusIDBetweenDates(int statusID, String startDate, String endDate) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(
"select count(*) from Task" +
" where StatusID=" + statusID + " and AssignDate between '" + startDate + "' and '" + endDate + "'", null);
int total = 0;
if (cursor.moveToFirst())
total = cursor.getInt(0);
cursor.close();
return total;
}
答案 2 :(得分:0)
SELECT *
的查询将返回表中所有行的所有列。
cursor.getInt(0)
返回光标当前行第一列的值。
要计算行数,您可以使用SELECT COUNT(*) ...
的查询,并读取其返回的值。或者,使用有用的helper function为您构建查询:
public int getTasksByStatusIDBetweenDates(int statusID, String startDate, String endDate) {
SQLiteDatabase db = this.getReadableDatabase();
return DatabaseUtils.queryNumEntries(
db, "Task",
"StatusID=" + statusID + " and AssignDate between ? and ?",
new String[]{ startDate, endDate });
}