Solved

ADODB AddNew method

Posted on 2000-05-15
6
929 Views
Last Modified: 2010-05-18
I am trying to add a new record and populate the fields using a Loop, but its not working, any ideas?  Its listed under the comments DEBUG.

Thank you
Anthony
cgsabol@seanet.com

========================================<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Registration</title>
</head>

<body>
<%
      Dim adoConn                  ' ADODB Connection Object
      Dim adoRec                  ' ADODB Recordset Object
      Dim strFields(8)      ' Data from Registration Form
      Dim strColumn(8)      ' Column Names
      Dim strConnString      ' SQL Statement
      Dim i                        ' Counter            
      
      strFields(0)= Request.Form("txtUserName")
      strFields(1) = Request.Form("txtFirstName")
      strFields(2) = Request.Form("txtMiddleName")
      strFields(3) = Request.Form("txtLastName")
      strFields(4) = Request.Form("txtBirthDay")
      strFields(5)= Request.Form("txtEmail")
      strFields(6)= Request.Form("txtHomePage")
      strFields(7) = Request.Form("txtPassword")
      
      strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
       "Data Source=\\p350\wwwroot\Anthony\Test\ww\gene.mdb;" & _
       "User Id=admin;" & _
       "Password=;"
       
   ' Create Connection/Recordset objects
      Set adoConn = CreateObject("ADODB.Connection")
      Set adoRec = CreateObject("ADODB.Recordset")
      
      adoConn.Open strConnString
      adoRec.Open "tblUserInfo", adoConn, 3, 3
      
      '-------------------------------------------------------------------------
      ' Check for null Values in the data being sent from the Registration Form.
      ' If we have a null value change it to a empty string
      Do Until i = Ubound(strFields) + 1
            If IsNull(strFields(i)) Then strFields(i) = ""
            i = i + 1
      Loop
      '--------------------------------------------------------------------------
      i = 0 ' Recycle variable

      adoRec.AddNew ' Add a new record
      
      ===DEBUG===================================================================
      '----DOES NOT WORK!
      'Do Until i = Ubound(strFields) + 1
            'adoRec.Fields(i).Value = strFields(i)
            'i = i + 1
      'Loop
      
      '----DOES NOT WORK!
      'Do Until i = Ubound(strFields) + 1
            'adoRec(i) = strFields(i)
            'i = i + 1
      'Loop
      
      '===========================================================================
      
      '----DOES WORK------------------------------------------------------------
      ' Write data to the Columns in the database
      adoRec.Fields("strUserName")=strFields(0)
      adoRec.Fields("strFirstName")=strFields(1)
      adoRec.Fields("strMidName")=strFields(2)
      adoRec.Fields("strLastName")=strFields(3)
      adoRec.Fields("dtmBirthday")=strFields(4)
      adoRec.Fields("strEmail")=strFields(5)
      adoRec.Fields("strHomePage")=strFields(6)
      adoRec.Fields("strPassword")=strFields(7)
      '-----------------------------------------------------------------------------
      
      adoRec.Update
      adoRec.Close
      
      Set adoConn = Nothing
      Set adoRec = Nothing
%>
      
<BR>
<H1 ALIGN="CENTER">Thank you <%Response.Write(strFields(0))%></H1>
<BR>

<TABLE>
      <TR><TD>UserName:</TD><TD><%Response.Write(strFields(0))%></TD></TR>
      <TR><TD>First Name:</TD><TD><%Response.Write(strFields(1))%></TD></TR>
      <TR><TD>Middle Initial:</TD><TD><%Response.Write(strFields(2))%></TD></TR>
      <TR><TD>Last Name:</TD><TD><%Response.Write(strFields(3))%></TD></TR>
      <TR><TD>Birthday:</TD><TD><%Response.Write(strFields(4))%></TD></TR>
      <TR><TD>Email::</TD><TD><%Response.Write(strFields(5))%></TD></TR>
      <TR><TD>Homepage:</TD><TD><%Response.Write(strFields(6))%></TD></TR>
      <TR><TD>Password:</TD><TD><%Response.Write(strFields(7))%></TD></TR>
</TABLE>

</body>

</html>
0
Comment
Question by:toys032498
6 Comments
 
LVL 4

Accepted Solution

by:
mberumen earned 122 total points
ID: 2813259
have you tried this statement?

===DEBUG===================================================================
                     i=0
                     Do Until i = Ubound(strFields) + 1
                      adoRec.Fields(i) = strFields(i)
                      i = i + 1
                      Loop
                     '===========================================================================
0
 
LVL 3

Expert Comment

by:Hencah
ID: 2813387
have tried this ??

adoRec.AddNew
i=0
Do Until i = Ubound(strFields) + 1
  adoRec.Fields(i)= strFields(i)
  i = i + 1
Loop


0
 
LVL 3

Expert Comment

by:Hencah
ID: 2813389
oops didn't mean to duplicate mbrumen's
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:mtieland
ID: 2813756
I recommand specifying a sql statement instead of a tablename so you can manage the order the fields are presented to you. And a command object could in some strange cases be a solution as wel.

example:

set Cmd1 = Server.CreateObject("adodb.command")
Cmd1.ActiveConnection = adoConn
Cmd1.CommandText = "select strUserName, strFirstname, strMidName, strLastName, dtmBirthday, strEmail, strHomepage, strPassword from tblUserInfo"
adoRec.Open Cmd1, , 3, 3

I do find your connectionstring somewhat strange too, you should maybe try this (if this is a access file...):

adoDb.ConnectionString = "DBQ=\\p350\wwwroot\Anthony\Test\ww\gene.mdb;UID=admin;PWD=;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;}"

Hope this helps,

good luck (Some seem to interpet this wrong)(I mean good luck in general)

Martijn
0
 

Expert Comment

by:mtieland
ID: 2813774
ps.

You should use this kind of loop:
adorec.addnew
for i = 0 to Ubound(strFields)
 adorec(i)=strFields(i)
next
adorec.update

One other thing I found out is:
When a new record is inserted you can start reading the values from the record only after requerying the table.
(Access only)

Martijn
0
 
LVL 1

Author Comment

by:toys032498
ID: 2834549
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now