Solved

Passing checkbox info

Posted on 2011-09-08
4
309 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 75

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

825 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