Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 9th, 2004, 11: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


Reply With Quote
  #2 (permalink)  
Old May 9th, 2004, 01: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
Reply With Quote
  #3 (permalink)  
Old May 9th, 2004, 02: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?

Reply With Quote
  #4 (permalink)  
Old May 9th, 2004, 09: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.
======================================
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:26 PM
Insert new record ID levinho Classic ASP Databases 5 January 14th, 2004 12:03 PM



All times are GMT -4. The time now is 05:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.