Link to home
Start Free TrialLog in
Avatar of Tagom
Tagom

asked on

Passing checkbox info

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

Avatar of kaufmed
kaufmed
Flag of United States of America image

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

Avatar of Tagom
Tagom

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tagom

ASKER

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