Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTC Checkboxes ?? 1

Status
Not open for further replies.

tpiro

Programmer
Aug 2, 2001
3
US
Looking for a sample using checkbox (DTC) I have three checkboxes, each one bound to its own DTC recordset. I am trying to find the correct syntax to read the data from the checkbox's recordset and set the checkbox to "checked" or "unchecked" depending on its recordset. Then, if I change the check box data, it writes it back to its recordset with an update button. I'm using SQL Server 7 and the data field for the checkbox is type bit. . . or it can be anything else if you choose. I would greatly appreciate your help and thank you in advance.

TP
 

TEST1152239.ASP:

<%@ Language=VBScript %>
<%
Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;DSN=TT&quot; ' You must change this
Set oRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

if Request.Form(&quot;fSubmit&quot;) = &quot;Y&quot; then
' UPDATE the database
if Request.Form(&quot;fOne&quot;)=&quot;on&quot; then cOne=1 else cOne=0
if Request.Form(&quot;fTwo&quot;)=&quot;on&quot; then cTwo=1 else cTwo=0
if Request.Form(&quot;fThree&quot;)=&quot;on&quot; then
cThree=1
else
cThree=0
end if

' The test database has 4 fields, 1 id and 3 bit fields
cSQL = &quot;UPDATE TTTEST set &quot; &_
&quot;one = &quot; & cOne & &quot;,&quot; &_
&quot;two = &quot; & cTwo & &quot;,&quot; &_
&quot;three= &quot; & cThree & &quot;WHERE ID=1&quot;
oConn.Execute(cSQL)

end if

' RETRIEVE values from database
cSQL = &quot;SELECT TOP 1 * FROM TTTEST WHERE ID=1&quot;
oRS.Open cSQL, oConn

Response.Write &quot;Retrieved values: &quot; & oRS(1) &_
&quot;, &quot;& oRS(2) & &quot; & &quot; & oRS(3) & &quot;<br>&quot;

Response.Write &quot;<form method=post action=test115239.asp>&quot; &_
&quot;<input type=hidden name=fSubmit value=Y>&quot; &_
&quot;One : <input type=checkbox name=fOne&quot;
if oRS(1) then response.write &quot; checked&quot;
Response.Write &quot;><br>Two :<input type=checkbox name=fTwo&quot;
if oRS(2) then response.write &quot; checked&quot;
Response.Write &quot;><br>Three:<input type=checkbox name=fThree&quot;
if oRS(3) then response.write &quot; checked&quot;
Response.Write &quot;><br><input type=submit></form>&quot;

%>



???? br
Gerard
 
The DTC Checkbox can save directly to a bit column, as well as a varchar and int columns:
Checked Unchecked Unchecked(NotNullable)
bit 1 Null 0
varchar True Null False[but this fails!]
tinyint 255 Null 0
smallint -1 Null 0
int -1 Null 0

via the default checkbox DTC bindings.
NOTE: ANY Non Zero/Null value is seen as 'true' by the checkbox - which is why the Non-Nullable varchar fails (the value 'False' is not null or zero - daft though this is!).

The code under the update button could be:
Sub pbUpdate_onclick()
'save any changes to the recordset
'--could manually 'fix' column values here too
' but best to place this in the rs_BeforeUpdate event
' because DTC's only tell the recordset about updates
' DURING the updateRecord method..
' So any column 'fixes' could be overwritten here
rsCheckBoxTest.updateRecord
End Sub

[all using server-side script] (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top