Solved

Passing checkbox info

Posted on 2011-09-08
4
302 Views
Last Modified: 2012-05-12
I have an application that I am working on for a volunteer group
I am trying to add a checkbox to the form
If the patient has delivered it should pass a 1 - or true
If the patient has not it should pass a 0 or fall
The database is Access - The column is yes/no default value is false - 0
I do ont get any errors when passing the data however when the checkbox is clicked to indicate true is does not pass any information

 
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<form runat="server" action = "InsertNames.aspx" method = "post">
      
      Please enter  Patients Name:
      <input type = "Text" name = "text1"   style="color: red" size="20" />
      <br /><br />
      
      Please enter Patients Address:
      <input type = "Text" name = "text2"   style="color: red" size="20" />
      <br /><br />
      
      Delivered:
    <input id="text3" type="checkbox" />   

    <br /><br />
      <input type="Submit">
  </form>

</body>

</html>

Open in new window

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

        Dim objConnection As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim strConnection As String
        Dim strSQL As String
	
        strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=Teens.mdb"
  
        ' Create and open the connection object
        objConnection = New OleDbConnection(strConnection)
        objConnection.Open()
	
	
        strSQL = "INSERT INTO teens(Pname, Paddress, Delivered)" & _
               " VALUES ( '" & Request.Form("text1") & "' , '" & Request.Form("text2") & "','" & Request.Form("text3") & "')"
	
	
        ' Create the Command and set its properties
        objCmd = New OleDbCommand(strSQL, objConnection)
	
        ' execute the command
        objCmd.ExecuteNonQuery()

        lblStatus.Text = "Command run"

    End Sub

</script>

<html>
  <body>
	<h2>Insert Data into Table</h2>
	<asp:Label id="lblStatus" runat="server"/>
	<p>
	   
  </body>
 
</html>

Open in new window

0
Comment
Question by:Tagom
  • 2
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36507545
Try this:

Delivered:
<input id="text3" type="checkbox" value="True" />

Open in new window


' Create and open the connection object
objConnection = New OleDbConnection(strConnection)
objConnection.Open()


strSQL = "INSERT INTO teens(Pname, Paddress, Delivered) VALUES (?, ?, ?)"

' Create the Command and set its properties
objCmd = New OleDbCommand(strSQL, objConnection)

objCmd.Parameters.Add(new OleDbCommand("text1", Request.Form("text1")))
objCmd.Parameters.Add(new OleDbCommand("text2", Request.Form("text2")))
objCmd.Parameters.Add(new OleDbCommand("text3", If(Request.Form("text3") IsNot Nothing AndAlso Request.Form("text3").Lenth > 0, Request.Form("text3"), "False")))

' execute the command
objCmd.ExecuteNonQuery()

Open in new window

0
 

Author Comment

by:Tagom
ID: 36507603
New code gave same results
asp
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

        Dim objConnection As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim strConnection As String
        Dim strSQL As String
	
        strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=Teens.mdb"
  
        ' Create and open the connection object
        objConnection = New OleDbConnection(strConnection)
        objConnection.Open()
	
	
        strSQL = "INSERT INTO teens(Pname, Paddress, Delivered) VALUES (?, ?, ?)"
	
	
        ' Create the Command and set its properties
        objCmd = New OleDbCommand(strSQL, objConnection)
        objCmd.Parameters.Add(New OleDbCommand("text1", Request.Form("text1")))
        objCmd.Parameters.Add(New OleDbCommand("text2", Request.Form("text2")))
        objCmd.Parameters.Add(New OleDbCommand("text3", If(Request.Form("text3") IsNot Nothing AndAlso Request.Form("text3").Lenth > 0, Request.Form("text3"), "False")))
        ' execute the command
        objCmd.ExecuteNonQuery()

        lblStatus.Text = "Command run"

    End Sub

</script>

<html>
  <body>
	<h2>Insert Data into Table</h2>
	<asp:Label id="lblStatus" runat="server"/>
	<p>
	   
  </body>
 
</html>

Open in new window


HTML
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<form runat="server" action = "InsertNames.aspx" method = "post">
      
      Please enter  Patients Name:
      <input type = "Text" name = "text1"   style="color: red" size="20" />
      <br /><br />
      
      Please enter Patients Address:
      <input type = "Text" name = "text2"   style="color: red" size="20" />
      <br /><br />
      
      Delivered:
    <input id="text3" type="checkbox" value="True" />

    <br /><br />
      <input type="Submit">
  </form>

</body>

</html>

Open in new window

0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36508479
You need to convert text3 value (which is string currently) to boolean using ConvertToBoolean
0
 

Author Comment

by:Tagom
ID: 36508603
This is the code I used
I get a dataType mismatch error:
Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System" %> 

<script language="VB" runat="server">

    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

        Dim objConnection As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim strConnection As String
        Dim strSQL As String
        	
        strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=Teens2.mdb"
  
        ' Create and open the connection object
        objConnection = New OleDbConnection(strConnection)
        objConnection.Open()
        
        strSQL = "INSERT INTO teens(Pname, Paddress, Delivered)" & _
                                  " VALUES ( '" & Request.Form("text1") & "' , '" & Request.Form("text2") & "','" & Convert.ToBoolean(Request.Form("text3")) & "')"
	
        	
        ' Create the Command and set its properties
        objCmd = New OleDbCommand(strSQL, objConnection)
       
        
        ' execute the command
        objCmd.ExecuteNonQuery()

        lblStatus.Text = "Command run"

    End Sub

</script>

<html>
  <body>
	<h2>Insert Data into Table</h2>
	<asp:Label id="lblStatus" runat="server"/>
	<p>
	   
  </body>
 
</html>

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now