Generic Database Record Insertion Script

Results 1 to 2 of 2

Thread: Generic Database Record Insertion Script

  1. #1
    Join Date
    Dec 1969

    Default Generic Database Record Insertion Script

    Hello everyone:<BR>trying to insert into multiple tables from single page:<BR><BR>I used the script exactly from the site with the exception of modifying the connection to my database. I also use a SQL Server database not Access. The error occurs at line 38, which is when the code tries to iterate through the table names.<BR><BR>Thanks for helping out a Newbie!!<BR>Chris<BR><BR>I get the following error when using your script from the "Generic Database Record Insertion Script " tutorial :<BR><BR>Error Type:<BR>Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)<BR>Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.<BR><BR><BR><BR><BR>This is the code:<BR>&#060;%@LANGUAGE="VBSCRIPT"%&#062;<BR>&#0 60;%<BR>Option Explicit<BR><BR><BR>&#039Our ADO constants we&#039ll need<BR>Const adOpenForwardOnly = 0<BR>Const adLockOptimistic = 3<BR>Const adCmdTable = &H0002<BR><BR>&#039Create our connection object and open a connection to our database<BR>Dim objConn<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR><BR>obj Conn.ConnectionString = "dsn=HALResume;uid=IUSR_DIGINET1;"<BR>objConn.Open <BR><BR>&#039Create a recordset object<BR>Dim objRS<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR><BR>&#03 9Open a table view for the table name specified by Request("TableName")<BR>Dim strTableName<BR>strTableName = Request("TableName")<BR><BR>objRS.Open strTableName, objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable<BR><BR><BR>&#039Add a new record...<BR>objRS.AddNew<BR><BR>&#039Iterate through the fields of the table...<BR>Dim fld<BR>For Each fld in objRS.Fields<BR> &#039If a value for the column name was passed in,<BR> &#039set the column name equal to the value passed through the form...<BR> if Len(Request(fld.Name)) &#062; 0 then<BR> fld.Value = Request(fld.Name)<BR> end if<BR>Next<BR><BR><BR>&#039We&#039re done, so update the record<BR>objRS.Update<BR><BR><BR>&#039Clean Up...<BR>objRS.Close<BR>Set objRS = Nothing<BR><BR>objConn.Close<BR>Set objConn = Nothing<BR><BR><BR>&#039Send the user to some confirmation page<BR>Response.Redirect "RecordAdded.htm"<BR><BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default Bill's Mantra: DEBUG DEBUG DEBUG

    I don&#039t know what is failing, but you will never know either unless you do some experimentation and debugging.<BR><BR>Examples: <BR><BR>Add Response.Write lines to display the field names and values that you are attempting to add/insert.<BR><BR>Remove most of the form fields...perhaps leaving in only one at a time, but a different one each run of the see if it is a particular field name/field value that causes the problem.<BR><BR>Et cetera. Those are just for starters. There are proably about 100 or more different things you could try. The trick in programming is to figure out what the most likely ones are and try them first. Sometimes, it really is number 100, and it takes a *long* time to find it. But once you get a little experience, you&#039ll usually find the problem in the top 10 or so things you look at.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts