473,385 Members | 1,834 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,385 software developers and data experts.

Inserting into Access Database

27
Hey all! need some help editing this script. The problem i keep running into is that i do not know how to change the insert into statement to insert the USER_ID and two other variables called path1 and path2. I keep getting syntax errors when i try to change it my self. Also the USER_ID which is coming from a cookie is not working well either. It tells me that its not declared when i put it into the insert into statement. Im using Windows XP with IIS 5.1. The page is a ASPX

Thanks!

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language=VB Debug=true %>
  2. <% 
  3. Dim USER_ID
  4. USER_ID = request.cookies("USER_ID").value%>
  5. <%@ Import Namespace="System.Data" %>
  6. <%@ Import Namespace="System.Data.OLEDB" %>
  7. <script runat=server>
  8. Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
  9.     Dim DBConn as OleDbConnection
  10.     Dim DBAdd As New OleDbCommand
  11.     DBConn = New OleDbConnection( _
  12.         "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
  13.         & "DATA SOURCE=" _
  14.         & Server.MapPath("DB/db1.mdb;"))
  15.     DBAdd.CommandText = "Insert Into Employee (" _
  16.         & "LastName, FirstName ) values (" _
  17.         & "'" & Replace(txtLastName.Text, "'", "''") _
  18.         & "', " _
  19.         & "'" & Replace(txtFirstName.Text, "'", "''") _
  20.         & "')"
  21.     DBAdd.Connection = DBConn
  22.     DBAdd.Connection.Open
  23.     DBAdd.ExecuteNonQuery()
  24. End Sub
  25. </SCRIPT>
  26.  
Jul 12 '07 #1
6 1367
dip_developer
648 Expert 512MB
Hey all! need some help editing this script. The problem i keep running into is that i do not know how to change the insert into statement to insert the USER_ID and two other variables called path1 and path2. I keep getting syntax errors when i try to change it my self. Also the USER_ID which is coming from a cookie is not working well either. It tells me that its not declared when i put it into the insert into statement. Im using Windows XP with IIS 5.1. The page is a ASPX

Thanks!

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language=VB Debug=true %>
  2. <% 
  3. Dim USER_ID
  4. USER_ID = request.cookies("USER_ID").value%>
  5. <%@ Import Namespace="System.Data" %>
  6. <%@ Import Namespace="System.Data.OLEDB" %>
  7. <script runat=server>
  8. Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
  9. Dim DBConn as OleDbConnection
  10. Dim DBAdd As New OleDbCommand
  11. DBConn = New OleDbConnection( _
  12. "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
  13. & "DATA SOURCE=" _
  14. & Server.MapPath("DB/db1.mdb;"))
  15. DBAdd.CommandText = "Insert Into Employee (" _
  16. & "LastName, FirstName ) values (" _
  17. & "'" & Replace(txtLastName.Text, "'", "''") _
  18. & "', " _
  19. & "'" & Replace(txtFirstName.Text, "'", "''") _
  20. & "')"
  21. DBAdd.Connection = DBConn
  22. DBAdd.Connection.Open
  23. DBAdd.ExecuteNonQuery()
  24. End Sub
  25. </SCRIPT>
  26.  
give your full sql query which you are using
Jul 12 '07 #2
radcaesar
759 Expert 512MB
Hey what is the exact error message u got ?
Jul 12 '07 #3
slider
27
give your full sql query which you are using
umm that is the full SQL query....not unless you want the rest of the HTML page

Hey what is the exact error message u got ?
i get just a error message saying i have caused a syntax error. It comes up becuase i have no clue what so ever.

The script works when i do not change it. It will get a first name and a last name out of two text fields and write them to the database. I need this script to write a USER_ID which is extracted from a cookie and to also write two variables called IMG and THUMB into the fields in the database called USER_ID, IMG, and THUMB

hope this makes it more understandable
Jul 12 '07 #4
radcaesar
759 Expert 512MB
U had unnecessarily use the concat operators in many places.

Just Have a break point in that line and see the returned query string which was returned.

There you will see your fault.

Remove the unnecessary & operators.
Check the Replace() mthod u use as string.

:)
Jul 12 '07 #5
radcaesar
759 Expert 512MB
Proceed it like this,

"Insert Into Employee (LastName, FirstName ) values (Replace(" &txtLastName.Text& ","
Jul 12 '07 #6
slider
27
Hey! Thanks a lot it all works now!
However my only problem now is the USER_ID. I can insert other cookie values into the database such as nicknames but not the USER_ID which is a numeric value such as 123.

When i run the page i get this error

System.NullReferenceException: Object reference not set to an instance of an object.

EG
Expand|Select|Wrap|Line Numbers
  1. dim userID 
  2. userID = request.cookies("USER_ID").value
  3.  
Any help would be great
Jul 12 '07 #7

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

Similar topics

14
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program...
7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
3
by: James Alba | last post by:
Hey all, I am accessing an ms access database using .NET and C#. Like so, /* Create the database connection. */ connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data...
15
by: yzlin04 | last post by:
Hello, I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table. There is no error message comes out when i run my program, but when i check my MS Access table,...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
0
by: SL Culby | last post by:
Hello everyone, I have a project where I pull SQL Server data put it into a dataset and now I have to put the dataset data into an Access Database. The dataset currently is over 2000 row, so looping...
2
by: joeey | last post by:
I'm doing an online registration form and using ODBC to connect to my database. I'm new to programming thus I do not know most of the advance features for php and Access. I need help in inserting...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.