Sql2000 storing and retrieve checkbox value..

P

Priyal

Hi,

I am using VisualStudio 2008 and Sql server 2000..

I have one website where i got many check boxes...

I am able to store the value of the checkbox and retrieve when i want to
edit..
Now sql 2000 store value as True and False for checked and notchecked...

Now what i want to do is.. i want to store value as y if checkbox is checked
and n if checkbox is notchecked..
And when i retrieve i need to see my checkbox ticked if it got value y and
not ticked if it got value n in sql 2000 database.

Currently i use this to retrieve
<asp:CheckBox ID = "chksw1" runat = "server" Checked = <%# partnerrow("sw1")
%>></asp:CheckBox>

And i use this string to insert value of checkbox into database.

insertsql = "UPDATE tbltest SET sw1='" & chksw1.Checked & "', sw2= '" &
chksw2.Checked & "' WHERE merchantid ='" & id & "'"

Any help will be appreciated.

Regards

Priyal
 
A

Alberto Poblacion

Priyal said:
I am using VisualStudio 2008 and Sql server 2000..

I have one website where i got many check boxes...

I am able to store the value of the checkbox and retrieve when i want to
edit..
Now sql 2000 store value as True and False for checked and notchecked...

Now what i want to do is.. i want to store value as y if checkbox is
checked and n if checkbox is notchecked..
And when i retrieve i need to see my checkbox ticked if it got value y and
not ticked if it got value n in sql 2000 database.

Currently i use this to retrieve
<asp:CheckBox ID = "chksw1" runat = "server" Checked = <%#
partnerrow("sw1") %>></asp:CheckBox>

And i use this string to insert value of checkbox into database.

insertsql = "UPDATE tbltest SET sw1='" & chksw1.Checked & "', sw2= '" &
chksw2.Checked & "' WHERE merchantid ='" & id & "'"

Any help will be appreciated.

Given the syntax that you are using in your insert string, it looks like
you are using VB and not C#, so the question is probably in the wrong group.
Anyway, in order to insert y/n instead of true/false, you could use an
inline conditional in your insertsql line. The following is the C# syntax;
in VB you could do the same thing with IIF:

insertsql = "UPDATE tbltest SET sw1="+(chksw1.Checked?"'y'":"'n'")+", sw2="+
(chksw2.Checked?"'y'":"'n'") + "' WHERE merchantid ='" + id + "'";

Note, however, that the recommended practice is not to concatenate the
values into the sql string, but to parameterize the string and provide the
values through parameters.

On the select part, you could similarly use an expression to check the
value for y/n:

<asp:CheckBox ID = "chksw1" runat = "server" Checked =
'<%# partnerrow("sw1")=="y" %>'</asp:CheckBox>

Once again, the "==" is C# syntax; VB would use a single "=".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top