kalosneri
06-16-2005, 05:10 AM
i have use a repeat region to call a data from data base mysql.
when i want to change the data and save/update again in data base.
but the data cannot save/update.
this is my cording:-
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/stock_conn.asp" -->
<%
Dim maincode
maincode =""
If (Request.form("maincode") <> "") Then
main=Request.form("maincode")
End If
%>
<%
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
strText = Replace(Request("s_code" & arrRecIDs(i)), "'", "''")
strText1 = Replace(Request("qty" & arrRecIDs(i)), "'", "''")
strText2 = Replace(Request("uom" & arrRecIDs(i)), "'", "''")
strTex3 = Replace(Request("desp" & arrRecIDs(i)), "'", "''")
set conS=server.CreateObject("ADODB.Connection")
set rsS=server.CreateObject("ADODB.Recordset")
cnS = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=stock"
conS.open cnS
rsS.open "SELECT * FROM assembly where s_code = '" & arrRecIDs(i) &"'",conS,3,2
If rsS.BOF = true THEN
x = 1 'add
Else
x= 0 'update
End if
'=================================================================================================== ====
if x = 1 AND s_code <> ""then
sqlUpdate= "UPDATE assembly set "
sqlUpdate = sqlUpdate & "qty='" &qty& "',"
sqlUpdate = sqlUpdate & "uom='" &uom& "',"
sqlUpdate = sqlUpdate & "s_code='" &s_code& "',"
sqlUpdate = sqlUpdate & "desp='" &desp& "',"
sqlUpdate = sqlUpdate & "maincode='" &main& "'"
sqlUpdate = sqlUpdate & " WHERE s_code='" &s_code& "'"
conS.Execute sqlUpdate
end if
rsS.close
next
end if
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_stock_conn_STRING
Recordset1.Source = "SELECT * FROM stock.assembly WHERE maincode = '" &main& "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<script language="JavaScript" type="text/JavaScript">
function add(){
assembly.action="asstable_add.asp";
assembly.submit();
}
</script>
<script language="JavaScript">
function RecUpdate(s_code){
var ThisID = "*" + (s_code) + "*"
if (document.assembly.hidRecIDs.value == ""){ // If the hidden field is empty
document.assembly.hidRecIDs.value = (ThisID) // Store the value in the hidden field (hidRecIDs) as it is.
}
if (document.assembly.hidRecIDs.value != ""){ // If the hidden field isn't empty
var str = document.assembly.hidRecIDs.value; // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID); // Search str to see if this RecID is allready in it.
if (pos == -1) { // If the position returned is -1 it isn't allredy in there,
document.assembly.hidRecIDs.value = document.assembly.hidRecIDs.value + ", " + (ThisID)
} // so add ", " and this ID to what is already in hidRecIDs
} // to create a list like this *2*, *5*, *8* etc.
}
//-->
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<form name="assembly" method= "post" >
<BODY bgcolor="white" text="black" link="#8000FF" vlink="gray" alink="teal" background="file:///C|/Pos_test/images/color.gif">
<div align="center">
<table width="64%" border="0" align="center">
<tr>
<td width="18%">Transaction</td>
<td width="14%"> <input name="maincode" type="text" id="maincode" value="<%=maincode%>">
</td>
<td width="68%">
<input type="submit" name="Submit4" value="Submit"></td>
</tr>
</table>
<table width="64%" border="0">
<tr>
<td width="18%"> </td>
<td width="9%"> </td>
<td width="73%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p> </p>
<table width="46%" border="0" align="center">
<tr>
<td width="28%">Main code</td>
<td width="4%">:</td>
<td width="68%">
<input name="main" type="text" id="main" value="<%=main%>">
</td>
</tr>
</table>
<table width="431" border="1" align="center" cellpadding="1" cellspacing="1">
<!--DWLayoutTable-->
<tr>
<td width="132"><div align="center">Stock code</div></td>
<td width="60"><div align="center">Qty</div></td>
<td width="108"><div align="center">Uom</div></td>
<td width="108"><div align="center">Desp</div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<% intRecID =(Recordset1.Fields.Item("s_code").Value)%>
<tr>
<td>
<div align="center">
<input name="s_code<%= intRecID %>" type="text" id="s_code" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("s_code").Value)%>" size="22">
</div></td>
<td>
<div align="center">
<input name="qty<%= intRecID %>" type="text" id="qty"onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("qty").Value)%>" size="10">
</div></td>
<td>
<div align="center">
<input name="uom<%= intRecID %>" type="text" id="uom"onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("uom").Value)%>" size="18">
</div></td>
<td>
<div align="center">
<input name="desp<%= intRecID %>" type="text" id="desp" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("desp").Value)%>" size="18">
</div></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<p> </p>
<p>
<input name="hidRecIDs" type="text" size="40">
<input type="submit" name="Submit2" value="Add" onclick="add();">
<input name="Submit" type="submit" value="Save" onclick="RecUpdate();">
</p>
<p> </p>
</div>
</body>
</form>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
what can i changes to make this data can update in data base??
when i want to change the data and save/update again in data base.
but the data cannot save/update.
this is my cording:-
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/stock_conn.asp" -->
<%
Dim maincode
maincode =""
If (Request.form("maincode") <> "") Then
main=Request.form("maincode")
End If
%>
<%
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
strText = Replace(Request("s_code" & arrRecIDs(i)), "'", "''")
strText1 = Replace(Request("qty" & arrRecIDs(i)), "'", "''")
strText2 = Replace(Request("uom" & arrRecIDs(i)), "'", "''")
strTex3 = Replace(Request("desp" & arrRecIDs(i)), "'", "''")
set conS=server.CreateObject("ADODB.Connection")
set rsS=server.CreateObject("ADODB.Recordset")
cnS = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=stock"
conS.open cnS
rsS.open "SELECT * FROM assembly where s_code = '" & arrRecIDs(i) &"'",conS,3,2
If rsS.BOF = true THEN
x = 1 'add
Else
x= 0 'update
End if
'=================================================================================================== ====
if x = 1 AND s_code <> ""then
sqlUpdate= "UPDATE assembly set "
sqlUpdate = sqlUpdate & "qty='" &qty& "',"
sqlUpdate = sqlUpdate & "uom='" &uom& "',"
sqlUpdate = sqlUpdate & "s_code='" &s_code& "',"
sqlUpdate = sqlUpdate & "desp='" &desp& "',"
sqlUpdate = sqlUpdate & "maincode='" &main& "'"
sqlUpdate = sqlUpdate & " WHERE s_code='" &s_code& "'"
conS.Execute sqlUpdate
end if
rsS.close
next
end if
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_stock_conn_STRING
Recordset1.Source = "SELECT * FROM stock.assembly WHERE maincode = '" &main& "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<script language="JavaScript" type="text/JavaScript">
function add(){
assembly.action="asstable_add.asp";
assembly.submit();
}
</script>
<script language="JavaScript">
function RecUpdate(s_code){
var ThisID = "*" + (s_code) + "*"
if (document.assembly.hidRecIDs.value == ""){ // If the hidden field is empty
document.assembly.hidRecIDs.value = (ThisID) // Store the value in the hidden field (hidRecIDs) as it is.
}
if (document.assembly.hidRecIDs.value != ""){ // If the hidden field isn't empty
var str = document.assembly.hidRecIDs.value; // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID); // Search str to see if this RecID is allready in it.
if (pos == -1) { // If the position returned is -1 it isn't allredy in there,
document.assembly.hidRecIDs.value = document.assembly.hidRecIDs.value + ", " + (ThisID)
} // so add ", " and this ID to what is already in hidRecIDs
} // to create a list like this *2*, *5*, *8* etc.
}
//-->
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<form name="assembly" method= "post" >
<BODY bgcolor="white" text="black" link="#8000FF" vlink="gray" alink="teal" background="file:///C|/Pos_test/images/color.gif">
<div align="center">
<table width="64%" border="0" align="center">
<tr>
<td width="18%">Transaction</td>
<td width="14%"> <input name="maincode" type="text" id="maincode" value="<%=maincode%>">
</td>
<td width="68%">
<input type="submit" name="Submit4" value="Submit"></td>
</tr>
</table>
<table width="64%" border="0">
<tr>
<td width="18%"> </td>
<td width="9%"> </td>
<td width="73%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p> </p>
<table width="46%" border="0" align="center">
<tr>
<td width="28%">Main code</td>
<td width="4%">:</td>
<td width="68%">
<input name="main" type="text" id="main" value="<%=main%>">
</td>
</tr>
</table>
<table width="431" border="1" align="center" cellpadding="1" cellspacing="1">
<!--DWLayoutTable-->
<tr>
<td width="132"><div align="center">Stock code</div></td>
<td width="60"><div align="center">Qty</div></td>
<td width="108"><div align="center">Uom</div></td>
<td width="108"><div align="center">Desp</div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<% intRecID =(Recordset1.Fields.Item("s_code").Value)%>
<tr>
<td>
<div align="center">
<input name="s_code<%= intRecID %>" type="text" id="s_code" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("s_code").Value)%>" size="22">
</div></td>
<td>
<div align="center">
<input name="qty<%= intRecID %>" type="text" id="qty"onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("qty").Value)%>" size="10">
</div></td>
<td>
<div align="center">
<input name="uom<%= intRecID %>" type="text" id="uom"onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("uom").Value)%>" size="18">
</div></td>
<td>
<div align="center">
<input name="desp<%= intRecID %>" type="text" id="desp" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("desp").Value)%>" size="18">
</div></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<p> </p>
<p>
<input name="hidRecIDs" type="text" size="40">
<input type="submit" name="Submit2" value="Add" onclick="add();">
<input name="Submit" type="submit" value="Save" onclick="RecUpdate();">
</p>
<p> </p>
</div>
</body>
</form>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
what can i changes to make this data can update in data base??