VB form is adding new rows in database but the new rows do not contain the form data.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mattjmacdonald
    New Member
    • Aug 2010
    • 2

    VB form is adding new rows in database but the new rows do not contain the form data.

    I have a form that i want to be saved to my database. The form is adding a new record to my sql server 2005 database but it is not bringing the text over with it. The new record in my db is just an empty row. Here is my code.

    Add to database section ( i have removed the connectionstrin g for privacy reasons)

    Code:
    <%@ Page aspcompat="true" Debug="true"  %>
    
    <html>
    <head>
    <title>Form to database</title>
    </head>
    <body> 
    <%
    'declare your variables
        Dim FirstName, LastName, Comments, MRN, Age, CathDate
        Dim sConnString, connection, sSQL
    'Receiving values from Form, assign the values entered to variables
        FirstName = Request.Form("FirstName")
        LastName = Request.Form("LastName")
        Comments = Request.Form("Comments")
        MRN = Request.Form("MRN")
        Age = Request.Form("Age")
        CathDate = Request.Form("CathDate")
    'declare SQL statement that will query the database 
        sSQL = "INSERT into tblPatientInfoTest (FirstName, LastName, Comments, MRN, Age, CathDate) values ('" & _
    FirstName & "', '" & LastName & "', '" & Comments & "', '" & MRN & "', '" & Age & "', '" & CathDate & "')"
    'define the connection string, specify database
    'driver and the location of database
        
    
    'create an ADO connection object 
        connection = Server.CreateObject("ADODB.Connection")
    
        'Open the connection to the database 
    connection.Open(sConnString)
    
    'execute the SQL 
    connection.execute(sSQL)
    
        Response.Write("The form information was inserted successfully.")
    'Done. Close the connection object
    connection.Close
        connection = Nothing
    %>
    </body>
    </html>
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    If there is no data, but there is a new row, it most likely means that there is no value in the variables you're trying to insert. Set a breakpoint at line 22 and check the value of sSQL.

    Apart from that, you still haven't explicitly told your variables of what type they are. You should really do that as it will come back to you to bite you in the butt ;-)

    Steven

    Comment

    Working...