Home > ASP Development > Update problems!

Update problems!



hi guys

i m using MS Access! I have this page "EditProduct.asp", which has 2 boxes which gets filled according to the Product Id i send from previous page.



i Want to existing data in those 2 boxes and when user edit the data, i send the data to same page, update db and then redirect to the previous page.



The problem i m facing is that when i edit the data, one field shows me numbers like "-1" or "0" and the other field just show me the same data as before editing!!



This is the code, need help!!


Code:


<%
Dim strProdId, rstShow, strShow
Dim strProductID, strProdName, strProdCode, strEdit
'this strProdIs is coming from previous page
strProdId = Request("pid")

If strProdId <> "" then
Set rstShow = Server.CreateObject("ADODB.Recordset")
strShow = "Select * From tblProductMaster Where Product_Id=" & strProdId
rstShow.Open strShow, Conn,adOpenStatic,adLockOptimistic
End If

'These values r coming thru postback of this page
strProductID = Request("ProdId")
strProdName = Request("txtProductName")
strProdCode = Request("txtProductCode")

If strProdName <> "" And strProdCode <> "" Then
strEdit = "Update tblProductMaster Set Product_Name='" & strProdName & "' And Product_Code='" & strProdCode & "' Where Product_Id=" & strProductID
Conn.Execute(strEdit)
Conn.close
Response.Redirect("AddProduct.asp")
End If
%>

<form action="EditProduct.asp" method="post" name="frmProduct" id="frm1">
<input type="hidden" name="ProdId" value="<%=strProdId%>">

<center>
<table border="1" cellspacing="2" cellpadding=2 bordercolor="#505050" width=400>
<TBODY>
<tr>
<th colspan=2 align="middle" bgcolor="#0050b0">
<font color="white" face=Tahoma size=3>Edit Product</font></th>
</tr>
<tr>
<td>
<table border="0" cellspacing="2" cellpadding=2 bordercolor="maroon" width=400>
<TBODY>
<tr>
<td align="right"><br><FONT face=Tahoma size=2>Product Name* : </FONT></td>
<td><br><input name="txtProductName" style="WIDTH: 190px; HEIGHT: 22px" tabIndex=1 value=<%Response.Write(rstShow("Product_Name"))%>></td>
</tr>
<tr>
<td align="right"><FONT face=Tahoma size=2>Product Code* : </FONT></td>
<td><INPUT style="WIDTH: 190px; HEIGHT: 22px" tabIndex=2 name=txtProductCode value=<%Response.Write(rstShow("Product_Code"))%>></td>
</tr>
</form>
<tr>
<td colspan="2" align="middle">
<input type="submit" name="btnSubmit" value="Save" id="cmd1" style="WIDTH: 80px; HEIGHT: 26px" tabIndex=3></td>
</tr></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER>
<P>&nbsp;</P>

<%
rstShow.Close()
Conn.Close
%>




Thanx

    
Guest


Quote:
Originally Posted by micky
hi guys

i m using MS Access! I have this page "EditProduct.asp", which has 2 boxes which gets filled according to the Product Id i send from previous page.



i Want to existing data in those 2 boxes and when user edit the data, i send the data to same page, update db and then redirect to the previous page.



The problem i m facing is that when i edit the data, one field shows me numbers like "-1" or "0" and the other field just show me the same data as before editing!!



This is the code, need help!!


Code:


<%
Dim strProdId, rstShow, strShow
Dim strProductID, strProdName, strProdCode, strEdit
'this strProdIs is coming from previous page
strProdId = Request("pid")

If strProdId <> "" then
Set rstShow = Server.CreateObject("ADODB.Recordset")
strShow = "Select * From tblProductMaster Where Product_Id=" & strProdId
rstShow.Open strShow, Conn,adOpenStatic,adLockOptimistic
End If

'These values r coming thru postback of this page
strProductID = Request("ProdId")
strProdName = Request("txtProductName")
strProdCode = Request("txtProductCode")

If strProdName <> "" And strProdCode <> "" Then
strEdit = "Update tblProductMaster Set Product_Name='" & strProdName & "' And Product_Code='" & strProdCode & "' Where Product_Id=" & strProductID
Conn.Execute(strEdit)
Conn.close
Response.Redirect("AddProduct.asp")
End If
%>

<form action="EditProduct.asp" method="post" name="frmProduct" id="frm1">
<input type="hidden" name="ProdId" value="<%=strProdId%>">

<center>
<table border="1" cellspacing="2" cellpadding=2 bordercolor="#505050" width=400>
<TBODY>
<tr>
<th colspan=2 align="middle" bgcolor="#0050b0">
<font color="white" face=Tahoma size=3>Edit Product</font></th>
</tr>
<tr>
<td>
<table border="0" cellspacing="2" cellpadding=2 bordercolor="maroon" width=400>
<TBODY>
<tr>
<td align="right"><br><FONT face=Tahoma size=2>Product Name* : </FONT></td>
<td><br><input name="txtProductName" style="WIDTH: 190px; HEIGHT: 22px;" tabIndex="1" value="<%Response.Write(rstShow("Product_Name"))%>"></td>
</tr>
<tr>
<td align="right"><FONT face=Tahoma size=2>Product Code* : </FONT></td>
<td><INPUT style="WIDTH: 190px; HEIGHT: 22px;" tabIndex="2" name="txtProductCode" value="<%Response.Write(rstShow("Product_Code"))%>"></td>
</tr>
</form>
<tr>
<td colspan="2" align="middle">
<input type="submit" name="btnSubmit" value="Save" id="cmd1" style="WIDTH: 80px; HEIGHT: 26px" tabIndex=3></td>
</tr></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER>
<P>&nbsp;</P>

<%
rstShow.Close()
Conn.Close
%>




Thanx




try the above bolded changes ... all i really did was put in quotes around the attributes. see if that makes a difference

Was this answer helpful ? Yes No   
Guest


Sorry Mehere, it didint work!!

no difference at all!

Thanx anyway

Was this answer helpful ? Yes No   
Guest


your update statement is wrong, you should have gotten error message.

try debugging with such code:


Code:



Response.Write("name: "&strProdName&"<br />code: "&strProdCode&"<br />")
If strProdName <> "" And strProdCode <> "" Then
strEdit = "Update tblProductMaster Set Product_Name='" & strProdName & "', Product_Code='" & strProdCode & "' Where Product_Id=" & strProductID
Response.Write("Updating... sql is: "&strEdit&"<br />")
Response.END
Conn.Execute(strEdit)
Conn.close
Response.Redirect("AddProduct.asp")
End If



Was this answer helpful ? Yes No   
Guest


hi micky...in update if we want to update more than one field than for field sepration we use , not and.. "and" part we use in where clause...if i m sure than than ur statement will not give any error it will take any value..

change this


Code:



strEdit = "Update tblProductMaster Set Product_Name='" & strProdName & "' And Product_Code='" & strProdCode & "' Where Product_Id=" & strProductID






to


Code:



strEdit = "Update tblProductMaster Set Product_Name='" & strProdName & "' , Product_Code='" & strProdCode & "' Where Product_Id=" & strProductID



Was this answer helpful ? Yes No   
Guest


Thanx Shadow and Guddu for pointing that one!

it might have nor shown any error because it got redirected!

i'll do this change and let u people know

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by micky
Thanx Shadow and Guddu for pointing that one!

it might have nor shown any error because it got redirected!

i'll do this change and let u people know
nope, when error is happening the script stops. dunno why it didn't crash with error...

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by Shadow Wizard
dunno why it didn't crash with error...
Dr. Watson, the plot thickens!

may b i wrote crash-proof code

Was this answer helpful ? Yes No   
Guest


Thanx Shadow and Guddu

it worked

Was this answer helpful ? Yes No   
Guest


glad your problem is sorted...micky

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved