473,387 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 connectionstring for privacy reasons)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page aspcompat="true" Debug="true"  %>
  3.  
  4. <html>
  5. <head>
  6. <title>Form to database</title>
  7. </head>
  8. <body> 
  9. <%
  10. 'declare your variables
  11.     Dim FirstName, LastName, Comments, MRN, Age, CathDate
  12.     Dim sConnString, connection, sSQL
  13. 'Receiving values from Form, assign the values entered to variables
  14.     FirstName = Request.Form("FirstName")
  15.     LastName = Request.Form("LastName")
  16.     Comments = Request.Form("Comments")
  17.     MRN = Request.Form("MRN")
  18.     Age = Request.Form("Age")
  19.     CathDate = Request.Form("CathDate")
  20. 'declare SQL statement that will query the database 
  21.     sSQL = "INSERT into tblPatientInfoTest (FirstName, LastName, Comments, MRN, Age, CathDate) values ('" & _
  22. FirstName & "', '" & LastName & "', '" & Comments & "', '" & MRN & "', '" & Age & "', '" & CathDate & "')"
  23. 'define the connection string, specify database
  24. 'driver and the location of database
  25.  
  26.  
  27. 'create an ADO connection object 
  28.     connection = Server.CreateObject("ADODB.Connection")
  29.  
  30.     'Open the connection to the database 
  31. connection.Open(sConnString)
  32.  
  33. 'execute the SQL 
  34. connection.execute(sSQL)
  35.  
  36.     Response.Write("The form information was inserted successfully.")
  37. 'Done. Close the connection object
  38. connection.Close
  39.     connection = Nothing
  40. %>
  41. </body>
  42. </html>
  43.  
Aug 16 '10 #1
1 1320
MrMancunian
569 Expert 512MB
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
Aug 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steveo | last post by:
Hi I have a form containing some text boxes and a button. I'm trying to work out how to make it so that if certain textboxes contain no data then the button is not enabled (however still...
2
by: HKM | last post by:
Hello ! I have extended DataGrid Control as per my requirements. My questions is how to add this Custom Data Grid to the Form (that I want this customized grid to appear). Following are the...
10
by: Assimalyst | last post by:
Hi, I'm attempting to use a data reader to load data from a single table, tblCountry, with two columns, countryNo (the Key) and countryName, into a DropDownList box. Here's the code: ...
4
by: Reny | last post by:
how do i limit the number of rows in a windows form data grid?
5
by: johnny | last post by:
hi all, I wonder if I could do the following task in PHP before searching for javascript which I prefer not to have in my code: I have a form to create new tables in a database and, since I...
8
by: Ragbrai | last post by:
Howdy all, I have a form for entering data (Form A), on which is a cmd button that opens Form B in acdialog mode to allow me to enter/edit records that are being displayed on Form A. After...
0
by: asad56 | last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
3
by: =?Utf-8?B?V2FsaWQ=?= | last post by:
Hello: I have migrated a site from IIS5 to IIS6. The site is configured and the we app is installed on the new IIS site. I can get to the web page but when I try to login, this is what I get...
1
by: Paddy | last post by:
The problem I am facing is as follows: I am populating an HTML table on my webpage with rows of data from a database. The rows may be sometimes 10 and sometimes say,3. I have two buttons on that...
2
by: mariaz | last post by:
Hello, I am creating a project where I parse an xml page (feed from a website) in a javabean file and I insert the parsed data in a mysql database. I want this data that gets inserted into the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.