This topic is locked
[SOLVED]

 Only one row's Boolean==true in a table

4/27/2016 2:35:16 AM
ASPRunner.NET General questions
C
ccvvccc author

I hope I can explain my case.
Imagine a DB table, and there is a Column in it. Type is Bit.
Lets say, there are 5 rows.

1 False

2 False

3 False

4 False

5 False


In edit view, If I change the third row's column to True, is it possible to make others false?
I want only one True in all rows in my table. When I make one True, all the others should be False. That's my case. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=23811&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />
In other words, When I edit one row, all the other rows should be edited. Is that possible?
Thanks for any ideas.

T
Tim 4/27/2016

I think I'd do something like this:
In the "After record updated" event:

if (values["MyColumn"] == "True") {
string sql = "UPDATE MyTable set MyColumn = 'False' where ID <> " + values["ID"].ToString() ;

CommonFunctions.db_exec(sql, null);
}


This assumes your table is called MyTable and it has 2 columns called ID and MyColumn.
I think this should work.

Tim

jadachDevClub member 4/27/2016

You can also do this by using a trigger.

C
ccvvccc author 5/4/2016



You can also do this by using a trigger.


Do you mean SQL Trigger? Or Asprunner.net has a Trigger mechanism that I dont know?

jadachDevClub member 5/4/2016

SQL Server Trigger

C
ccvvccc author 5/16/2016



I think I'd do something like this:
In the "After record updated" event:

if (values["MyColumn"] == "True") {
string sql = "UPDATE MyTable set MyColumn = 'False' where ID <> " + values["ID"].ToString() ;

CommonFunctions.db_exec(sql, null);
}


This assumes your table is called MyTable and it has 2 columns called ID and MyColumn.
I think this should work.

Tim


@timnorvel thanks a lot. It works like a charm. There is no problem in edit mode. But there is always a "But" <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=79367&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
It works in inline edit as well. But It doesn't deselect previous checkboxes. They remain selected. If I manually refresh the page, I get what I want. The other checkboxes become deselected. Is there a way to solve it?

Sergey Kornilov admin 5/17/2016

You will have to refresh page from your code programmatically after this update.
https://xlinesoft.com/asprunnernet/docs/how_to_refresh_list_page_after_inline_add_edit.htm