Solved

Passing checkbox info

Posted on 2011-09-08
4
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Telerik RadEditor Control Save 8 40
EF5 How do I stop pre-compiled views? 8 56
What is GIS method of Geometry data type? 6 36
VB .net 2010 Byte array 2 24
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

752 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