Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2004, 10:55 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert a record into a Database

Im a student a Cleveland St Uninveristy and Im working a ASP.NET Web Application that suppossed to insert a new record in a database.
I have to turn this project in next Thursday.

The application has 3 area code and 3 phone text boxes. And 1 email text box.

Im trying to insert into a database the input from these text boxes.
Im putting the data from the area text boxes and phone text boxes into an array. Then I want to loop through the arrays and insert the data into a database. Here is my code below:
variable e1 holds the email address.

Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Dim myCNN As New ADODB.Connection
        Dim mySQL As String
        Dim counter As Integer
        Dim registerDate As DateTime = Today
        Dim expireDate As DateTime = Today.AddYears(5)


        myCNN.Open("DSN=MyDoNotCall")
        counter = 0
        For counter = 1 To 3
            mySQL = "Insert INTO Master(PatronEmail,AreaCode,PhoneNumber,Registrati onDate,ExpirationDate) VALUES (e1,area(counter),phone(counter),registerDate,expi reDate)"
        Next
        myCNN.Close()
        myCNN = Nothing
    End Sub

Can anyone let me know if this is the right way of doing this?
Any help would greatly appreciated.

Thanks Eric


 
Old May 9th, 2004, 12:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

If you are using ADO.NET, you should use the ADO.NET objects, System.Data, System.Data.SQLClient or OLEDB. You can do it that way, it's perfectly fine. you need to execute the SQL string though.

Brian
 
Old May 9th, 2004, 01:29 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked but it inserted null values in the database.
The arrays that are holding my data are currently in the Page_Load Procedure.

Do I need to take them out of the Page_Load?

 
Old May 9th, 2004, 08:50 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

ersp,
When you build the string to execute on hte sever, you need to add in the variable values dynamically.
The string you are passing uses the actual variable names not their values.
try something like this.
Code:
mySQL = "Insert INTO Master(PatronEmail,AreaCode,PhoneNumber,RegistrationDate,ExpirationDate) VALUES ('" & e1 & "','" & area(counter) & "','" & phone(counter) & "','" & registerDate & "','" & expireDate) & "'"
However this assumes that they are all string values of some sort, numeric values will not require the single quotation mark around the value.
eg (" & e1 & ", instead of ('" & e1 & "',
if eq is a numeric value in the database.

You can Response.Write(mySQL ) to see what the command looks like that you are acutally sending to the Database server.
I suggest trying to write out the mySQL value now and then when you have made the chages so you can see the difference.



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================




Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert where record doesn't already exist Neal SQL Server 2000 3 February 4th, 2008 10:09 AM
Insert new Record priority05 Classic ASP Databases 2 September 6th, 2004 12:26 PM
Insert new record ID levinho Classic ASP Databases 5 January 14th, 2004 12:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.