473,581 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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)

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 1334
MrMancunian
569 Recognized Expert Contributor
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
1444
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 visible). Firstly I can't work out how to make a button un-enabled (is this a word? i hope you know what i mean!) and secondly I'm not sure how to make...
2
2007
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 blocks of code. public class CustomDataGrid : DataGrid { public CustomDataGrid()
10
5326
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: protected System.Data.SqlClient.SqlConnection conn; protected System.Data.SqlClient.SqlDataReader drCountry;
4
1224
by: Reny | last post by:
how do i limit the number of rows in a windows form data grid?
5
6512
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 can't know how many columns needs each table, I want to load the page with a single text field in the form and then with a button adding more...
8
3854
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 adding/editing a record on Form B (opened in acDialog mode), I want a cmd button on Form B to close Form B and then have Form A automatically take me to...
0
1961
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 child of main form not working. Main form stil working but when try to open child a message show as Please select a valid...
3
7713
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 the following error below. I would appreciate any insight, direction or help regarding this. Thank-you!! Walid
1
1692
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 page "Next" and "Previous" which I want displayed just a couple of lines below the table dynamically. Thus the positions of these buttons would vary...
2
1951
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 database to be shown in my project when it deploys (the project is jsf and I am using NetBeans). What I want to ask is how can I update the data of the...
0
7882
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7914
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5683
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.