Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Monday, March 26, 2012

please help

error message
=============
Microsoft JET Database Engine- Error '80040e14'

Syntax error (comma) in query expression 'id=67, 68'.

C:\sambar60-1\home\kenny\manage\userdelete.asp, line 105

cn.execute(sql)

=====================================================

member.asp
===========
<!--#include file="cnndb.asp"-->
<%
set rs=server.createobject("ADODB.Recordset")
sql="select * from Users order by userNo"
rs.open sql,cn,1,1
%
<html>
<head>
<title>MEMBER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
td {
font-family: "Verdana";
font-size: 14px;
color: #000000;
text-decoration: none;
}
body {
font-family: "Verdana";
font-size: 14px;
color: #000000;
text-decoration: none;
}
-->
</style>
<script languagge="javascript">
function checkdata(){

if (document.form1.userno.value==""){
alert("PLEASE INSERT USER NO");
document.form1.userno.focus();
return false;
}

document.form1.submit();
}
function confirmdel1(filename){
if (!confirm("CONFIRM DELETE ("+filename+")?"))
{return false;
}
return true;
}
function confirmdel2(filename){
if (!confirm("CONFIRM SUSPEND ("+filename+")?"))
{return false;
}
return true;
}
function confirmedit(filename){
if (!confirm("CONFIRL EDIT ("+filename+")?"))
{return false;
}
return true;
}

function deleteRec()
{

if(confirm("CONFIRM DELETE?"))
{

document.form1.action="userdelete.asp";
document.form1.submit();
}
}

function suspentRec()
{

if(confirm("CONFIRM SUSPENT?"))
{

document.form1.action="userstop.asp";
document.form1.submit();
}
}

function resetRec()
{

if(confirm("CONFIRM RESET?"))
{

document.form1.action="userstatus.asp";
document.form1.submit();
}
}

function editRec()
{

if(confirm("CONFIRM Edit?"))
{

document.form1.action="useredit.asp";
document.form1.submit();
}
}

</script>
<style type="text/css">
<!--
a {
font-family: "Verdana";
font-size: 14px;
color: #0000FF;
text-decoration: underline;
}
a:hover {
font-family: "Verdana";
font-size: 14px;
color: #FF3300;
text-decoration: underline;
}
--
</style>
</head
<body bgcolor="#FFD21E"
<div align="center">
<form name="deleteform" method="post" action="userdelete.asp">
<table width="467" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#000000" width="469">
<table width="469" border="0" cellspacing="1" cellpadding="0">
<tr align=center>
<td height="25" colspan="5" bgcolor="#CC0033" width="467"><font color="#FFFFFF" size="3">MEMBER
LISTINGS
<input type="button" name="Button2" onClick="document.location='member.asp'" value=" REFRESH " style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 20px">
</font></td>
</tr>
<tr align=center bgcolor="#000099">
<td width="99" height="20"><font color="#FFFFFF">USR</font></td>
<td width="99" height="20"><font color="#FFFFFF">PWD</font></td>
<td width="148" height="20"><font color="#FFFFFF">REMARKS</font></td>
<td width="50" height="5"><font color="#FFFFFF">SET</font></td>
<td width="67" height="20"></td>
</tr><% do while not rs.eof %>
<tr>
<td height="10" align="center" bgcolor="#F5f5f5" width="99"><font color="#0000FF"><%=rs("userNo")%></font></td>
<td height="10" align="center" bgcolor="#F5f5f5" width="99"><font color="#0000FF"><%=rs("ballpassword")%></font></td>
<td height="10" align="center" bgcolor="#F5f5f5" width="148"><font color="#0000FF"><%=rs("meno")%></font></td
<td align="center" valign="top" width="50" bgcolor="#F5f5f5"><input type="checkbox" name="deleted" value="<%=trim(rs("id"))%>"><%=trim(rs("id"))%
</font>
</td>
<td height="10" bgcolor="#F5f5f5" width="67"><div align="center"><font color="#ff0000">
<%
if trim(rs("pause"))="0" and trim(rs("status"))="0" then
response.write"<font color=black>OFF</font color>"
elseif trim(rs("pause"))="1" and trim(rs("status"))="0" then
response.write"SUSPENDED"
elseif trim(rs("pause"))="0" and trim(rs("status"))="1" then
response.write"ON"
elseif trim(rs("pause"))="1" and trim(rs("status"))="1" then
response.write"STOPPED"
else
response.write"ERROR"
end if
%>
</font></div></td>
</tr><% rs.movenext
if rs.eof then
exit do
end if
%>
<tr>
<td height="10" align="center" bgcolor="#FFFFD9" width="99"><font color="#0000FF"><%=rs("userNo")%></font></td>
<td height="10" align="center" bgcolor="#FFFFD9" width="99"><font color="#0000FF"><%=rs("ballpassword")%></font></td>
<td height="10" align="center" bgcolor="#FFFFD9" width="148"><font color="#0000FF"><%=rs("meno")%></font></td>
<td align="center" valign="top" width="50" bgcolor="#FFFFD9"><input type="checkbox" name="deleted" value="<%=trim(rs("id"))%>"><%=trim(rs("id"))%
</font></td>
<td height="10" bgcolor="#FFFFD9" width="67"><div align="center"><font color="#ff0000">
<% if trim(rs("pause"))="0" and trim(rs("status"))="0" then
response.write"<font color=black>OFF</font color>"
elseif trim(rs("pause"))="1" and trim(rs("status"))="0" then
response.write"SUSPENDED"
elseif trim(rs("pause"))="0" and trim(rs("status"))="1" then
response.write"ON"
elseif trim(rs("pause"))="1" and trim(rs("status"))="1" then
response.write"STOPPED"
else
response.write"ERROR"
end if
%>
</font></div></td>
</tr><% rs.movenext
if rs.eof then
exit do
end if
loop
%>
</table></td>
</tr>
</table>
<td align="right" colspan=13 bgcolor="#FFE1AD">
<input type="submit" value="Delete">
<input type="button" name=updateButton onClick="suspentRec()" value="Suspent">
<input type="button" name=resetButton onClick="resetRec()" value=" Reset ">
<input type="button" name=EditButton onClick="editRec()" value=" Edit "></form>
<br><form name="form1" method="post" action="testing.asp">
<table width=200 border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#99CC33">
<table height="109" border="0" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFD0">
<td height="20" colspan="2" width="214">
<p align="center"><font color="#FF0000" size="3">ADD NEW MEMBER</font></td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77" bgcolor="#FFFFD0">USER:</td>
<td width="130">
<input name="userno" type="text" id="userno" maxlength="20" size="17"> </td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">PWD:</td>
<td width="130">
<input name="password" type="password" id="password" maxlength="20" size="17"> </td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">REMARKS:</td>
<td width="130">
<input name="meno" type="text" id="meno" maxlength="100" size="17"></td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">TEL:</td>
<td width="130">
<input name="tel" type="text" id="tel" maxlength="100" size="17"></td>
</tr>
<tr bgcolor="#FFFFD0" align=center>
<td height="50" bgcolor="#FFFFD0" colspan=2><input type="button" name="Button" onClick="checkdata()" value="ENTER" style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 30px">
<input type="button" name="Button3" onClick="javascript:document.location='updateadmin.asp'" value="CHANGE PWD" style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 30px"></td>
</tr>
</table></td>
</tr>
</table>
</form></div>
<br>
<% rs.close
set rs=nothing
closeCN
%>
</body>
</html>
==========================================================

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id="&request("deleted")&""
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
=========================================================

please help me how can i query/loop the id so that it will delete the record 1 by 1?
ThanksCan you resume to the code related to the question only.
the code is only on userdelete.asp

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if Request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id="&Request("deleted")&""
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
========================================

error
====
Microsoft JET Database Engine- Error '80040e14'

Syntax error (comma) in query expression 'id=66, 67'.

C:\sambar60-1\home\kenny\manage\userdelete.asp, line 105

cn.execute(sql)

===========================================

if i only selected 1 record to delete in checkbox, the program will delete. But more than 1 ID, the program will error above.
You can not delete multiple records like that.

It does not like the id=66, 67. You need to do something like:

id IN (66, 67)
so how to fix the code?
i'm really stuck in this error for few days already.
Please help me...
Use namespace System.Text.RegularExpressions
Try out something as


Dim strValues As String = "67,68"
Dim FieldsValues() As String = Regex.Split(strValues, ",")
Dim x As String
For Each x In FieldsValues
'Put delete code here
Next


In userdelete.asp you have:

sql="delete * from Users where id="&Request("deleted")&""

Replace it with:

sql="delete * from Users where id IN (" & Request("deleted") & ")"

This way, if there is just one record it will still work, but if there are multiple selected it should handle them as well.
yes!!!! that's work....
much much thanks for your help mbradford
:)
mbradford, did you know how to code a soccer predictions competition program using asp?
:)
nope, just a lucky guess ;-)
mbradford, i facing a new problem now.

actually i have 4 function button after display records which is (Delete, Suspent, Reset, Edit).
justnow what you teach me is i'm using a form format (action="userdelete.asp"), but now how can i click the delete button it goes to userdelete.asp and when i click edit it goes to useredit.asp? and how to let my program carry out the ID together to the *.asp page?

i have some javascript code in my program,
=================================

document.form1.submit();
}
function confirmdel1(filename){
if (!confirm("CONFIRM DELETE ("+filename+")?"))
{return false;
}
return true;
}
function confirmdel2(filename){
if (!confirm("CONFIRM SUSPEND ("+filename+")?"))
{return false;
}
return true;
}
function confirmedit(filename){
if (!confirm("CONFIRL EDIT ("+filename+")?"))
{return false;
}
return true;
}

function deleteRec()
{

if(confirm("CONFIRM DELETE?"))
{

document.form1.action="userdelete.asp";
document.form1.submit();
}
}

function suspentRec()
{

if(confirm("CONFIRM SUSPENT?"))
{

document.form1.action="userstop.asp";
document.form1.submit();
}
}

function resetRec()
{

if(confirm("CONFIRM RESET?"))
{

document.form1.action="userstatus.asp";
document.form1.submit();
}
}

function editRec()
{

if(confirm("CONFIRM Edit?"))
{

document.form1.action="useredit.asp";
document.form1.submit();
}
}
===================================================

<input type="button" name=DeleteButton onClick="deleteRec()" value="Delete">
<input type="button" name=UpdateButton onClick="updateRec()" value="Suspent">
<input type="button" name=ResetButton onClick="resetRec()" value=" Reset ">
<input type="button" name=EditButton onClick="editRec()" value=" Edit "
This is the button which after listing all my records.
====================================================
In your form tag you currently have:

<form name="deleteform" method="post" action="userdelete.asp"
Try taking off:

action="userdelete.asp"

and then your javascript should take care of the submit
i have remove the action tag but the program still can't do any job i request. how now?
or i put the action tag (action="useraction.asp") new .asp page, and join all the code in userdelete.asp, userstatus.asp and userstop.asp?

how to join together so that when submit the button the program will know if it is delete button then goes to deleteuser code, suspent button then goes to userstop.asp?

can you give me some idea should i use javascript or merge these 3 files code together and how to merge?

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if Request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id IN ("&Request("deleted")&")"
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
====================================================

userstatus.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("id")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause,status from Users where id="&request("id")&""
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="0"
rs("status")="0"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script>
====================================

userstop.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("id")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause from Users where id="&request("id")&""
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="1"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script>
================================================

if using javascript, what should i do now? do you need the member.asp code?

Saturday, March 24, 2012

Please Help Datagrid Columns

I have a table called Computers with 8 colunms.

I have a select query that list out the Computer brand and the price.
what I want is that when I click on the computer brand then the respective information about this brand will be display in the same page or open a new page. I am using a datagrid, how do I make this work? or should I use other component like table.
Please helpIf you have unique Identifier for the Computerband table use it to create a hyperlink column in the datagrid. then pass the id as querystring. During the postback event read the Id get the details of the brand form from the id and then you can display that in formation in a panel below this grid.

Note;
1. AutoGenerateColumns property must be set to False
2. Manually Create DataGrid columns including the hyperlink column

Ex:


<asp:DataGrid id="dg1" AutoGenerateColumns="False" runat="server">
<asp:HyperLinkColumn Headertext="Brand Id" DataTextField="BrandId" DataNavigationUrlField="BrandId" DataNavigationUrlFormatString="ComputerBrands.aspx?brandId={0}" />
<asp:BoundColumn DataField="ComputerBrandName" HeaderText="Brand Name"/>
<!-- .... add other columns -->
</asp:DataGrid

Thanks
Thank you Jay.

I still have som problem, I create a procedure that reads
Create Proc GetComputerID

@.ComputerID int

as
Select Computer,Price,CPU from Computers
Where ComputerID = @.ComputerID

I do not know where to pass the parameter in the grid, and I could not type computerID={0}
vb.net would not even allow me to run the application
I removed the where claus from my statement. But when I click on the hyperlink, nothing happens.
Here is the ASP code:
<asp:HyperLinkColumn Text="Computer" Target="_self" DataNavigateUrlField="ComputerID" DataNavigateUrlFormatString="UsedComputer.aspx?ComputerId={0}"
DataTextField="Computer" HeaderText="Computer" NavigateUrl="Computer"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="ComputerID" HeaderText="ComputerID"></asp:BoundColumn>
</Columns>