C# sqlite选择行为
我使用sqlite.NETc 当我执行此语句时C# sqlite选择行为,c#,wpf,sqlite,C#,Wpf,Sqlite,我使用sqlite.NETc 当我执行此语句时 "SELECT id, date, team1, team2, finalScore, winner FROM matches WHERE team1 = @team OR team2 = @team AND date BETWEEN @fromDate AND @toDate ORDER BY date DESC" 忽略team2=@team,仅当team1=@team时选择。 如果我删除或team2=@team,则返回查询将为空,而不应为空。
"SELECT id, date, team1, team2, finalScore, winner FROM matches WHERE team1 = @team OR team2 = @team AND date BETWEEN @fromDate AND @toDate ORDER BY date DESC"
忽略team2=@team,仅当team1=@team时选择。
如果我删除或team2=@team,则返回查询将为空,而不应为空。
如果我将team1=@team或team2=@team放在括号中,则返回空查询
这是所有的代码
public System.Data.DataTable searchMatches(string team, string fromDate, string toDate)
{
SQLiteCommand cm = new SQLiteCommand("SELECT id, date, team1, team2, finalScore, winner FROM matches WHERE team1 = @team OR team2 = @team AND date BETWEEN @fromDate AND @toDate ORDER BY date DESC", cnlite);
cm.Parameters.AddWithValue("@team", team);
cm.Parameters.AddWithValue("@fromDate", fromDate);
cm.Parameters.AddWithValue("@toDate", toDate);
SQLiteDataAdapter sda = new SQLiteDataAdapter(cm);
System.Data.DataTable table = new System.Data.DataTable();
sda.Fill(table);
return table;
}
DataTable matches = db.searchMatches(sheetDataXlsx.Rows[i]["Ομαδα 1"].ToString(), matchDate.ToString("yyyy/MM/dd"),
matchDate.AddDays(-90).ToString("yyyy/MM/dd"));
PS日期是字符串yyyy/MM/dd,如中所述,其优先级高于或。
因此,您的查询相当于:
选择其中team1=?或者团队2=?日期在。。。
您必须手动添加括号以强制执行正确的求值顺序