简体   繁体   中英

reading bool values from database table and writing one bool value back to it

    //check if user has completed all five tasks
        OleDbConnection dbCon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\zoofari\zoofari\zoofari\MainData.accdb");

        OleDbDataAdapter dAdapter = new OleDbDataAdapter();

        DataSet ds = new DataSet();

        string query = ("select * from tbl_Tasks where Username = '" + _stuUname + "'");

        dbCon.Open();
        dAdapter = new OleDbDataAdapter(query, dbCon);

        OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
        DataTable dTable = new DataTable();
        dAdapter.Fill(dTable);

        dbCon.Close();

I'm trying to check if a user has completed 5 tasks (boolean value of true) before writing a true value to another field called 'Completed' in the same table. Do I need to create variables to hold the first five values or can I check this in one SQL statement? My SQL skills are very basic so please keep replies as simple as possible! thanks

You don't need to store any values at all. You can just run the query

UPDATE [tbl_Tasks] SET [Completed] = ([1] AND [2] AND [3] AND [4] AND [5])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM