Question triggering a SP from web

dkone

New member
Joined
Feb 4, 2015
Messages
1
Programming Experience
Beginner
Not sure if this is the correct forum for this, but I will try anyway. Hopefully I can phrase my question properly. Here is what I am attempting to accomplish:


I would like to use a checkbox value to be sent as a parameter to a SP when the submit button is clicked. The problem I am running into is that the checkbox by default will return the value of 'on' when checked and 'NULL' when not checked. This would be fine if the DB field was a string type, but it is not, it is an Int. (yes I know binary would be more appropriate, but it is not my DB and I can' change it). So my issue is one of converting the output of the checkbox to '1' if checked and either 'NULL' or '0' if not checked. I have a Var statement that does the conversion, but I think I am missing some fundamental step as the Var output is not being passed to the SP, just the default string output of the checkbox is. Here is the entirety of the web page. As it is it works as long as on my test DB I set the 'Valid' field to a string type.




So my question is actually two-fold, as there may be more than one way to solve this. What is wrong with my code that the Var statements output is not getting passed to the SP? or, can I convert the string output of the checkbox in the SP?






<%@Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">
private void InsertCard (object source, EventArgs e) {
SqlDataSource1.Insert();


string checkBoxValue = this.CheckBox1.Checked ? "1" : "0";
}






</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">






<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStringsevTestConnectionString %>"
insertcommand="AddMember" InsertCommandType="StoredProcedure">
<insertparameters>
<asp:FormParameter Name="CardNumber" formfield="CardNumberBox" Type="int32" />
<asp:FormParameter Name="NameFirst" formfield="NameFirstBox" Type="String" />
<asp:FormParameter Name="Valid" formfield="CheckBox1" Type="string" />
</insertparameters>
</asp:sqldatasource>


<br /><asp:textbox
id="CardNumberBox"
runat="server" />




<br /><asp:textbox
id="NameFirstBox"
runat="server" />


<br />


<asp:CheckBox id="CheckBox1" Text="Valid" runat="server" />




<br />
<asp:button
id="Button1"
runat="server"
text="Add Card"
onclick="InsertCard" />


</form>
</body>
</html>
 
Top Bottom