2013-05-01 52 views
1
//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(); 

我試圖在向另一個字段寫入真值之前檢查用戶是否完成了5個任務(布爾值爲true),名爲'Completed '在同一張桌子上。我是否需要創建變量來保存前五個值,或者我可以在一個SQL語句中檢查這些變量嗎?我的SQL技能非常基本,所以請儘可能簡單地回覆!謝謝從數據庫表中讀取bool值並寫回一個bool值

+0

您有SQL注入易變性 – SLaks 2013-05-01 15:10:19

+0

「tbl_Tasks」的列是什麼? – Arran 2013-05-01 15:15:10

+0

用戶名1 2 3 4 5完成 – LHammy 2013-05-01 15:16:17

回答

0

你根本不需要存儲任何值。您可以運行查詢

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

非常感謝你,這工作完美! – LHammy 2013-05-01 17:44:58