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

working with databases..

guys i have a html form that has action to redirect it to asp page,, dat asp page has vb script that recieves values from the form and add it to access db..out of those i hav two textboxes for which i have to keep a constant value.. but when i execute it,,it gives me error..how can i do it without manually entering values for dose 2 fields.. i want vbscript here is what i have those two fields are itemid and price..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
</head>

<body>
<%
' Declaring variables
Dim name, email, country, itemcode,price, data_source, con, sql_insert

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
name = ChkString(Request.Form("name"))
email = ChkString(Request.Form("email"))
country = ChkString(Request.Form("country"))
itemcode = ChkString(Request.Form("itemid"))
price = ChkString(Request.Form("price"))


data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("form.mdb")
sql_insert = "insert into users (name, email, country, itemid, price) values ('" & _
name & "', '" & email & "', '" & country & "' , '" & itemid & "' , '" & price & "')"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
' Done. Close the connection
con.Close
Set con = Nothing
Response.Write "All records were successfully entered into the database."
%>



</body>
</html>
May 20 '09 #1
4 1780
debasisdas
8,127 Expert 4TB
you can simply hard code the values or use some constant .

Please post the exact error message.
May 21 '09 #2
prabirchoudhury
162 100+
hey..next time try to wrap with [code] tag around your code please.. thanks..

1. you have to Set the Parameters values to to the parameters Collection and pass the string values.

2. you could replace name.Text with your scheck string value

Expand|Select|Wrap|Line Numbers
  1. Dim sql_insert As String = "INSERT INTO users (name, email, country, itemid, price) VALUES (@name, @email,@country,@itemid, @price )"
  2.         Dim cmd As New OleDb.OleDbCommand(sql_insert, data_source)
  3.         '   |||||   Set the Parameters values to to the parameters Collection
  4.         cmd.Parameters.AddWithValue("@name", name.Text)
  5.         cmd.Parameters.AddWithValue("@email", email.Text)
  6.         cmd.Parameters.AddWithValue("@country", country.Text)
  7.         cmd.Parameters.AddWithValue("@itemid", itemid.Text)
  8.         cmd.Parameters.AddWithValue("@price", price.Text)
  9.         conn.Open()
  10.         cmd.ExecuteNonQuery()
  11.         cmd.Dispose()
  12.         conn.Close()
  13.         lblResponse.Text = "Success!"
  14.  
  15.  
  16.  
  17.  
May 22 '09 #3
Hi to all,

Is there anyone know how to store images on a database, what are the procedures and also how to call? (citing an example would be appreciated) I know how to store data on a database like names, address, telephone number and other informations.. I used vb 6.0 and my backend is ms access.. anyone?! I need to know some of the concepts because I don't have any idea on it. very thanks if someone replies

=)
Jul 21 '09 #4
OuTCasT
374 256MB
Expand|Select|Wrap|Line Numbers
  1. function saveImage
  2.     <% 
  3.        Protected Sub Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Upload.Click
  4.         Dim fileUpload1 As FileUpload = CType(Me.FindControl("fileUpload1"), FileUpload)
  5.         'Make sure a file has been successfully uploaded
  6.         If fileUpload1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(fileUpload1.PostedFile.FileName) OrElse fileUpload1.PostedFile.InputStream Is Nothing Then
  7.             Label1.Text = "Please Upload Valid picture file"
  8.             Exit Sub
  9.         End If
  10.         'Check that it is a JPG or GIFF file
  11.         Dim extension As String = System.IO.Path.GetExtension(fileUpload1.PostedFile.FileName).ToLower()
  12.         Dim ImageType As String = Nothing
  13.          Select extension
  14.             Case ".gif"
  15.                 ImageType = "image/gif"
  16.             Case ".jpg", ".jpeg", ".jpe"
  17.                 ImageType = "image/jpeg"
  18.             Case ".png"
  19.                 ImageType = "image/png"
  20.             Case Else
  21.                 'Invalid file type uploaded
  22.                 Label1.Text = "Not a Valid file format"
  23.                 Exit Sub
  24.         End Select
  25.         'Connect to the database and insert a new record into Picture table
  26.         Dim myConnection As New SqlConnection("connectionString")
  27.         Const SQL As String = "INSERT INTO [Borrower] ([BorrowerPhoto]) VALUES (@ImageData)"
  28.         Dim myCommand As New SqlCommand(SQL, myConnection)
  29.  
  30.         'Load FileUpload's InputStream into Byte array
  31.         Dim imageBytes(fileUpload1.PostedFile.InputStream.Length) As Byte
  32.         fileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)
  33.         myCommand.Parameters.AddWithValue("@ImageData", imageBytes)
  34.         myCommand.Parameters.AddWithValue("@Company", TextBox1.Text.Trim())
  35.         myConnection.Open()
  36.         myCommand.ExecuteNonQuery()
  37.         myConnection.Close()
  38.           End Sub
  39.     %>
  40.     end function
Jul 21 '09 #5

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

Similar topics

0
by: Bill Gates | last post by:
i have two servers this is happenning on. each has a maintenance plan with the same options selected... General Tab - applies to all databases Optimizations Tab - reorganize data and index...
3
by: Raghuraman | last post by:
Hi, I was thinking abt linked servers deals only with multiple servers physically inter-connected. Now i come accross that we can link our non-sqlserver databases also. It is thru the...
6
by: RMG | last post by:
I use VS.net 2003 and VSS 6a. Whilst working on the network the integration between VS.net and VSS works perfectly. But when I open a project whilst disconnected from the network I get some...
24
by: Salad | last post by:
Every now and then I see ads that state something like "Experience with Large Databases ...multi-gig...blah-de-blah" And I have to laugh. What's the difference between a large or small database? ...
0
by: Mark B | last post by:
Our webhost (www.usbusinessweb.net) had a W2K IIS5 server crash after a scheduled hard-boot occurred during a ms-security patch install overnight. They couldn't get the server working again so they...
4
by: Development - multi.art.studio | last post by:
Hello to the List, i have a question about backing up my fresh updated databases :) after updating some of my databases, everything works fine, except my backupscripts. i run this script as...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
1
by: microsoft . public . sqlserver | last post by:
I am using SQL server 7.0. After restoring all the databses (Except distribution) Everything seems to be working fine except the backup maintenance plan. I put following detail in the maintenance...
1
by: mark4asp | last post by:
Help: SQLCacheDependency not working. When I step through my code with the debugger I notice that the condition below: (cacheItem == null) is always true. I have setup SQLCacheDependency...
3
by: Aswanth | last post by:
Hi.., I'm having Two Stored Procedures in Two Different Databases.. Database1 - Employee Stored Procedure - Employee_Details Database2 - Company Stored Procedure - Company_Details
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: 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: 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
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...

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.