Solved

problem getting data to insert.

Posted on 2011-09-07
6
375 Views
Last Modified: 2013-11-28
I have the two following files: The purpose is a small database for a volunteer organization to allow teen age girls to register with them online. The database is an access database - connection is already established.
Any ideas on what I am doing wrong in the code?

one is the .aspx that is supposed to insert data into a table
The other is the html form
The column types are: Text, Text, Yes/No, Date/Time
Data provided was susyQ, myDreamDr, Yes, 01/11/2011

I would like to be able to use a dataTime picker but have not got that far yet.

When I test them I get the following error
Data type mismatch in criteria expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:

Line 30:    
Line 31:     ' execute the command
Line 32:     objCmd.ExecuteNonQuery()
Line 33:
Line 34:     lblStatus.Text = "Command run"

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

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

  Sub Page_Load(Sender As Object, 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="
  
    ' Create and open the connection object
    objConnection = New OleDbConnection(strConnection)
    objConnection.Open()
    
    
	strSQL = "INSERT INTO teens(Pname, Paddress, delivered, Ddate)" & _
                    " VALUES ( '" & request.form("text1") & "' , '" & request.form("text2") & "' ,'" & request.form("text3") & "','" & request.form("text4") & "')"
	
	
	'strSQL = "INSERT INTO Employees (LastName)" & _
                   '   "VALUES ('" & request.form("text1") & "')" 

    ' 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

<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 />
      
      Has Patient Delivered:
      <input type = "Yes/No" name = "text2"   style="color: red" size="20" />
      <br /><br />
      
      Due Date:
      <input type = "Date/Time" name = "text2"   style="color: red" size="20" />
      <br /><br />
      

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

</body>

</html>

Open in new window

0
Comment
Question by:Tagom
  • 5
6 Comments
 

Author Comment

by:Tagom
Comment Utility
I already caught the duplicate names for the labels in the htm page.
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 total points
Comment Utility
OH the date for Access must be eclosed in # marks. not quotes, The yes/no is probaly going to a boolean field - no quotes at all pass eith 0 (false or No) or -1 (True/Yes)

Kelvin
0
 

Author Comment

by:Tagom
Comment Utility
I am not sure where to change it in the code - in the form part (htm) or the aspx part...
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:Tagom
Comment Utility
I changed the code to below

I get the following error
[OleDbException (0x80040e07): Data type mismatch in criteria expression.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1003520
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
   ASP.hgdeposition_teens_insertnames_aspx.Page_Load(Object Sender, EventArgs E) in \.....\InsertNames.aspx:32
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

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

  Sub Page_Load(Sender As Object, 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, Ddate)" & _
                    " VALUES ( '" & request.form("text1") & "' , '" & request.form("text2") & "' ,'" & request.form("text3") & "','" & request.form("#text4#") & "')"
	
	
	'strSQL = "INSERT INTO Employees (LastName)" & _
                   '   "VALUES ('" & request.form("text1") & "')" 

    ' 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
 

Author Comment

by:Tagom
Comment Utility
Starting from scratch -
I have both text fields inserting data correctly.
I then added a boolean to the table - I get the following error
So I am unsure how to code or pas the boolean - can someone please help me.
code is below:
 
<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 />
      
      Has Patient Delivered:
      <p>
        <label>
          Yes <input type="radio" name="test3" value="Yes" id="RadioGroup1_0">
          </label>
        <br>
        <label>
          No <input type="radio" name="test3" value="No" id="RadioGroup1_1">
         </label>
        <br>
      </p>
  

      <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(Sender As Object, 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") & "')"
	
	
	'strSQL = "INSERT INTO Employees (LastName)" & _
                   '   "VALUES ('" & request.form("text1") & "')" 

    ' 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


Data type mismatch in criteria expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:

Line 30:    
Line 31:     ' execute the command
Line 32:     objCmd.ExecuteNonQuery()
Line 33:
Line 34:     lblStatus.Text = "Command run"


Source File: \....\InsertNames.aspx    Line: 32

Stack Trace:

[OleDbException (0x80040e07): Data type mismatch in criteria expression.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1003520
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
   ASP.hgdeposition_teens_insertnames_aspx.Page_Load(Object Sender, EventArgs E) in \\.....\InsertNames.aspx:32
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
0
 

Author Closing Comment

by:Tagom
Comment Utility
Could not figure out how to pass data as the answer was vague
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

771 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

11 Experts available now in Live!

Get 1:1 Help Now