Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

Inserting Multiple records into a database

Posted 22 Oct 2006 23:20:03
1
has voted
22 Oct 2006 23:20:03 oyeyemi oliyide posted:
Hello Evryone,

I need someone to help me out with this. I use dreamweaver and asp.

I am retrieving some records from a recordset (which was made from two tables) within an access database and i want to be able to insert the records separately into another table in the database but what i get is everything get inserted into the database as one record(something like EmpID: (2,3,4) FirstName: (Oyeyemi, Gboya, Hilda) LastName: (Oliyide, Odulate, Dokubo)) instead of EmpID: (2) FirstName: (Oyeyemi) LastName: (oliyide) , EmpID: (3) FirstName: (Gboya) LastName: (Odulate), EmpID: (4) FirstName: (Hilda) LastName: (Dokubo) etc. I will paste the code i generated from dreamweaver below. I will be grateful if you can point out where the error is to me. Thank you in anticipation of your help.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="../loginrequired.asp"
MM_grantAccess=false
If Session("MM_Username" <> "" Then
If (true Or CStr(Session("MM_UserAuthorization")="" Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization")>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?" >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL"
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert") = "book_engr" Then

MM_editConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\domains\zionwebhosting.com\wwwroot\olivehrm\data\prologic.mdb"
MM_editTable = "BookEngr"
MM_editRedirectUrl = "engrBook_success.asp"
MM_fieldsStr = "JobID|value|EmployeeID|value|firstName|value|lastName|value"
MM_columnsStr = "JobID|',none,''|EmployeeID|',none,''|FirstName|',none,''|LastName|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert") <> "" Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","
MM_delim = MM_typeArray(0)
If (MM_delim = "none" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''" & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next

MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""


If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim rsBookEngr__MMColParam
rsBookEngr__MMColParam = "1"
If (Request.QueryString("JobID" <> "" Then
rsBookEngr__MMColParam = Request.QueryString("JobID"
End If
%>
<%
Dim rsBookEngr
Dim rsBookEngr_numRows

Set rsBookEngr = Server.CreateObject("ADODB.Recordset"
rsBookEngr.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\domains\zionwebhosting.com\wwwroot\olivehrm\data\prologic.mdb"
rsBookEngr.Source = "SELECT JobID, EmployeeID, FirstName, LastName FROM JobBookings, Engineers WHERE JobID = " + Replace(rsBookEngr__MMColParam, "'", "''" + ""
rsBookEngr.CursorType = 0
rsBookEngr.CursorLocation = 2
rsBookEngr.LockType = 1
rsBookEngr.Open()

rsBookEngr_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
rsBookEngr_numRows = rsBookEngr_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Book Job</title>
<style type="text/css">
<!--
.style2 {
font-family: Georgia, "Times New Roman", Times, serif;
font-weight: bold;
}
-->
</style>
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<div align="center">
<table width="700" height="359" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#6699FF">
<tr>
<td height="55" align="center" bgcolor="#6699FF"><span class="style2">Human Resources Application </span></td>
</tr>
<tr>
<td height="302"><form ACTION="<%=MM_editAction%>" METHOD="POST" id="book_engr" name="book_engr".Value)%>

<div align="center">
<p><u><strong>Book Engineer For Job </strong></u><br />
</p>
<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#999966">
<tr>
<td width="15%" bgcolor="#999966"><strong>JobID</strong></td>
<td width="19%" bgcolor="#999966"><strong>EmpolyeeID</strong></td>
<td width="23%" bgcolor="#999966"><strong>First Name </strong></td>
<td width="17%" bgcolor="#999966"><strong> Last Name </strong></td>
<td width="26%" bgcolor="#999966"><strong>Select Engineer </strong></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsBookEngr.EOF))
%>
<tr>

<td><label>
<input name="JobID" type="text" id="JobID" value="<%=(rsBookEngr.Fields.Item("JobID".Value)%>" />
</label></td>
<td><label>
<input name="EmployeeID" type="text" id="EmployeeID" value="<%=(rsBookEngr.Fields.Item("EmployeeID".Value)%>" />
</label></td>
<td><label>
<input name="firstName" type="text" id="firstName" value="<%=(rsBookEngr.Fields.Item("FirstName".Value)%>" />
</label></td>
<td><label>
<input name="lastName" type="text" id="lastName" value="<%=(rsBookEngr.Fields.Item("LastName".Value)%>" />
</label></td>
<td align="center"><label>
<input name="Insert" type="checkbox" id="Insert" value="Yes" />
</label></td>

</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsBookEngr.MoveNext()
Wend
%>
<tr>
<td colspan="4"> </td>
<td><label>
<input type="submit" name="Submit" value="Book Engineers" />
</label></td>
</tr>
</table>
<p><br />
</p>
</div>





<input type="hidden" name="MM_insert" value="book_engr">
</form>
</td>
</tr>
</table>
</div>

</body>
</html>
<%
rsBookEngr.Close()
Set rsBookEngr = Nothing
%>

Looking forward to hearing from you.

Thanks a lot.

Oyeyemi

Reply to this topic