null で更新

    public void updateScore(int id, ExeMode method, int? score) {
        string item = CommonDao.GetScoreItemName(method);
        // How to string format
        string sql = $"UPDATE LessonTable SET {item} ={(score == null ? "null" : score.ToString())} WHERE ID ={id}";

        dbManager.Execute(sql);
    }

項目を動的に変えてデータを取得

void Start()
{
	dbManager = this.GetComponentInParent();
}

public int GetScore(int id, ExeMode method)
{
	string item = CommonDao.GetScoreItemName(method);
	string sql = $"SELECT {item} FROM LessonTable WHERE ID=?";

	SimpleDataTable lists = dbManager.QueryGeneric(sql, id);

	if(lists.rows.Count ==0 ) {
		return 0;
	}
	return int.Parse(lists.rows[0][0].ToString());
}
© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha