Forums
This topic is locked
Unknow UPDATE multiple records ERROR
Posted 03 Jun 2009 02:12:14
1
has voted
03 Jun 2009 02:12:14 Ismael Ontiveros posted:
Hello!!I'm very new in all about programing so im sorry if my problem its silly
I'm following this tutorial www.drdev.net/article11.asp to upload multiple records in a ASP webpage and a DB from Access
Now, i want to upload several (3) "String" and "Integer" info but i get an ERROR when i add the second string call, i mean, the ASP bring me the info but doesnt uploaded. This happen olny when i add the second String or Integer
// THIS IS THE CODE THAT DOES THE UPLOAD //
<%
If Request("Submit" ) <> "" Then
intRecIDs = Replace(Request("hidRecIDs" ), "*", "" ) ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
arrRecIDs = Split(intRecIDs, ", " ) ' Create an array, wich will contain just the IDs of the records we need to update
For i = 0 to Ubound(arrRecIDs) ' Loop trough the array
strTxt = Replace(Request("txtText" & arrRecIDs(i)), "'", "''" ) "Text type of data"
intNum = Replace(Request("txtNum" & arrRecIDs(i)), "'", "''" ) "Numeric type of data"
boolPag = Replace(Request("selYes" & arrRecIDs(i)), "'", "''" ) "Yes/No type of data"
strNam = Replace(Request("txtName" & arrRecIDs(i)), "'", "''" ) "Text type of data" [!] i think here is the problem, cause without this it works fine
set commUpdate = Server.CreateObject("ADODB.Command" )
commUpdate.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../../../C4DMDBhost/TVE CRM.mdb" ) & ";Persist Security Info=False"
commUpdate.CommandText = "UPDATE TableCRM SET RecText = '" & strTxt & "', RecNum = '" & intNum & "', RecYes = '" & boolPag & "', RecName = '" & strNam & "' WHERE RecID = " & arrRecIDs(i)
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
Next
strMessage = " Listo"
Response.Redirect("MultiUpdateDemo_test.asp?Message=" & strMessage)
End If
%>
// THE CALL //
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command" )
Recordset1_cmd.ActiveConnection = MM_crmtve_STRING
Recordset1_cmd.CommandText = "SELECT RecID, RecText, RecNum, RecYes, RecName FROM TableCRM"
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
// THE ACTUAL FORM FOLLOWING THE TUTORIAL //
<tr>
<td nowrap>
<%= intRecID %><input name="hidRecID<%= intRecID %>" type="hidden" value="<%= intRecID %>" size="5">
</td>
<td nowrap>
<input name="txtText<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecText" ).Value)%>" size="20">
</td>
<td nowrap>
<input name="txtNum<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecNum" ).Value)%>" size="20">
</td>
<td nowrap>
<input name="selYes<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecYes" ).Value)%>" size="20">
</td>
<td nowrap>
<input name="txtName<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecName" ).Value)%>" size="20">
</td>
</tr>
Replies
Replied 06 Aug 2009 16:00:03
06 Aug 2009 16:00:03 Owen Eastwick replied:
Hi Ismael,
What is the error message you get when you run the page?
I think the problem is probably something to do with a mismatch of the data types you are trying to update and the database fields. For example when you are inserting or updating a text field, it will look like this:
If you are updating a numeric value, it will look something like this:
Notice that the value is not surrounded by single quotes.
Also, when you have boolean values, or you are using a checkbox in a form, you need to assign a value if none is provided through the form, ie. the checkbox is not ticked. For example:
I hope that helps.
What is the error message you get when you run the page?
I think the problem is probably something to do with a mismatch of the data types you are trying to update and the database fields. For example when you are inserting or updating a text field, it will look like this:
commUpdate.CommandText = "UPDATE tblName SET TextField='" & strText & "'"
If you are updating a numeric value, it will look something like this:
commUpdate.CommandText = "UPDATE tblName SET NumberField=" & intNumber
Notice that the value is not surrounded by single quotes.
Also, when you have boolean values, or you are using a checkbox in a form, you need to assign a value if none is provided through the form, ie. the checkbox is not ticked. For example:
boolChecked = Request.Form("chkTrueFalse") If boolChecked = "" Then boolChecked = false
I hope that helps.
Edited by - Owen Eastwick on 06 Aug 2009 16:01:25
Edited by - Owen Eastwick on 06 Aug 2009 16:02:04