Showing posts with label syntax. Show all posts
Showing posts with label syntax. 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 : System.Data.OleDb.OleDbException: Syntax error in IN

Hello All,

I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

And the line it shows in red is

cmd.ExecuteNonQuery()

I have pasted the entire code here. Can someone please give me some clue as what could be wrong. The SQL string looks fine because I pasted the resulting SQL in to MS Access. When I ran the Insert query, it properly added the record in the Access DB.

Thanks,

Joe

<%@dotnet.itags.org. Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source='E:/Inetpub/databases/investors.mdb'")
objConn.Open()

'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again.")
Response.Write("</A>")
Response.End()
End If

bolAlreadyExists = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()

Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) = 0) Then
Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop

objDataReader.Close()

If Not bolAlreadyExists Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor, RemoteIP
Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")

Dim MySQL as String

MySQL = "INSERT INTO Results(email, password, first_name, last_name, company, street_address, address2, city, state, country, postal, phone, mobile, AddDate, Inv, RemoteIP)" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_name & "', '" & company & "', '" & street_address & "', '" & address2 & "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '" & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "', '" & RemoteIP & "')"

Dim cmd as New OleDBCommand (MySQL, objConn)

cmd.ExecuteNonQuery ()
End if

objConn = Nothing
objConn.Close()

%I believe 'password' is a keyword - but it is also your column name. Try
putting [ and ] around the column name.

Alsok you shouldn't just concatenate strings together given to you by the
user. They could easily put in malicious SQL for one of those values. I
would recommend using parameters.

"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> Hello All,
> I am trying to insert a record in the MS Access DB and for some reason I
cannot get rid of error message,
> System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> And the line it shows in red is
> cmd.ExecuteNonQuery()
> I have pasted the entire code here. Can someone please give me some clue
as what could be wrong. The SQL string looks fine because I pasted the
resulting SQL in to MS Access. When I ran the Insert query, it properly
added the record in the Access DB.
> Thanks,
> Joe
>
> <%@. Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
> <%@. Import Namespace="System.Data.OleDb" %>
> <%@. Import Namespace="System.Data" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <%
> 'Open up a connection to Access database
> 'Using a DSN connection.
> Dim bolfFound, strUsername, bolAlreadyExists
> Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source='E:/Inetpub/databases/investors.mdb'")
> objConn.Open()
> 'check state
> If Session("strAdmin") <> "test" Then
> objConn.Close()
> objConn = Nothing
> Response.Write("<A HREF=index.aspx'>")
> Response.Write("Sorry, looks like your session timed out, please login
again.")
> Response.Write("</A>")
> Response.End()
> End If
> bolAlreadyExists = False
> Dim objDataReader as OledbDataReader
> Dim objCommand as New OledbCommand("Select * From Results", objConn)
> objDataReader = objCommand.ExecuteReader()
> Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
= 0) Then
> Response.Redirect("record_exists.aspx")
> bolAlreadyExists = True
> End If
> Loop
> objDataReader.Close()
> If Not bolAlreadyExists Then
> Dim Email, passwd, first_name, last_name, company, street_address,
address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
RemoteIP
> Email = Request.Form("Email")
> passwd = Request.Form("password")
> first_name = Request.Form("first_name")
> last_name = Request.Form("last_name")
> company = Request.Form("company")
> street_address = Request.Form("street_address")
> address2 = Request.Form("address2")
> city = Request.Form("city")
> prov = Request.Form("state")
> country = Request.Form("country")
> postal = Request.Form("postal")
> phone = Request.Form("phone")
> mobilePhone = Request.Form("mobile")
> AddDate = Now
> Inv = "Yes"
> RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> Dim MySQL as String
> MySQL = "INSERT INTO Results(email, password, first_name, last_name,
company, street_address, address2, city, state, country, postal, phone,
mobile, AddDate, Inv, RemoteIP)" & _
> " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"
> Dim cmd as New OleDBCommand (MySQL, objConn)
> cmd.ExecuteNonQuery ()
> End if
> objConn = Nothing
> objConn.Close()
> %
Yep..that got me a few times. Also Joe, be careful of using Date as a column name as well, I know you didn't use it here but I had to find out the hard way. It will cause the same type of error. The Jet Provider is picky about those kinds of words

"Marina" wrote:

> I believe 'password' is a keyword - but it is also your column name. Try
> putting [ and ] around the column name.
> Alsok you shouldn't just concatenate strings together given to you by the
> user. They could easily put in malicious SQL for one of those values. I
> would recommend using parameters.
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> > Hello All,
> > I am trying to insert a record in the MS Access DB and for some reason I
> cannot get rid of error message,
> > System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> > And the line it shows in red is
> > cmd.ExecuteNonQuery()
> > I have pasted the entire code here. Can someone please give me some clue
> as what could be wrong. The SQL string looks fine because I pasted the
> resulting SQL in to MS Access. When I ran the Insert query, it properly
> added the record in the Access DB.
> > Thanks,
> > Joe
> > <%@. Page Language="VB" Debug="true" ContentType="text/html"
> ResponseEncoding="iso-8859-1" %>
> > <%@. Import Namespace="System.Data.OleDb" %>
> > <%@. Import Namespace="System.Data" %>
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> > <%
> > 'Open up a connection to Access database
> > 'Using a DSN connection.
> > Dim bolfFound, strUsername, bolAlreadyExists
> > Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
> source='E:/Inetpub/databases/investors.mdb'")
> > objConn.Open()
> > 'check state
> > If Session("strAdmin") <> "test" Then
> > objConn.Close()
> > objConn = Nothing
> > Response.Write("<A HREF=index.aspx'>")
> > Response.Write("Sorry, looks like your session timed out, please login
> again.")
> > Response.Write("</A>")
> > Response.End()
> > End If
> > bolAlreadyExists = False
> > Dim objDataReader as OledbDataReader
> > Dim objCommand as New OledbCommand("Select * From Results", objConn)
> > objDataReader = objCommand.ExecuteReader()
> > Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> > If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
> = 0) Then
> > Response.Redirect("record_exists.aspx")
> > bolAlreadyExists = True
> > End If
> > Loop
> > objDataReader.Close()
> > If Not bolAlreadyExists Then
> > Dim Email, passwd, first_name, last_name, company, street_address,
> address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
> RemoteIP
> > Email = Request.Form("Email")
> > passwd = Request.Form("password")
> > first_name = Request.Form("first_name")
> > last_name = Request.Form("last_name")
> > company = Request.Form("company")
> > street_address = Request.Form("street_address")
> > address2 = Request.Form("address2")
> > city = Request.Form("city")
> > prov = Request.Form("state")
> > country = Request.Form("country")
> > postal = Request.Form("postal")
> > phone = Request.Form("phone")
> > mobilePhone = Request.Form("mobile")
> > AddDate = Now
> > Inv = "Yes"
> > RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> > Dim MySQL as String
> > MySQL = "INSERT INTO Results(email, password, first_name, last_name,
> company, street_address, address2, city, state, country, postal, phone,
> mobile, AddDate, Inv, RemoteIP)" & _
> > " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
> last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
> "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
> & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
> '" & RemoteIP & "')"
> > Dim cmd as New OleDBCommand (MySQL, objConn)
> > cmd.ExecuteNonQuery ()
> > End if
> > objConn = Nothing
> > objConn.Close()
> > %>
>

Please help : System.Data.OleDb.OleDbException: Syntax error in IN

Hello All,
I am trying to insert a record in the MS Access DB and for some reason I can
not get rid of error message,
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
And the line it shows in red is
cmd.ExecuteNonQuery()
I have pasted the entire code here. Can someone please give me some clue as
what could be wrong. The SQL string looks fine because I pasted the result
ing SQL in to MS Access. When I ran the Insert query, it properly added the
record in the Access DB.
Thanks,
Joe
<%@dotnet.itags.org. Page Language="VB" Debug="true" ContentType="text/html" ResponseEncodin
g="iso-8859-1" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w
3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data so
urce='E:/Inetpub/databases/investors.mdb'")
objConn.Open()
'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again
.")
Response.Write("</A>")
Response.End()
End If
bolAlreadyExists = False
Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()
Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) =
0) Then
Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop
objDataReader.Close()
If Not bolAlreadyExists Then
Dim Email, passwd, first_name, last_name, company, street_address, address2,
city, prov, country, postal, phone, mobilePhone, AddDate,Investor, RemoteIP
Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")
Dim MySQL as String
MySQL = "INSERT INTO Results(email, password, first_name, last_name, company
, street_address, address2, city, state, country, postal, phone, mobile, Add
Date, Inv, RemoteIP)" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_
name & "', '" & company & "', '" & street_address & "', '" & address2 & "',
'" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '" & ph
one & "', '" & mobilePho
ne & "', '" & AddDate & "', '" & Investor & "', '" & RemoteIP & "')"
Dim cmd as New OleDBCommand (MySQL, objConn)
cmd.ExecuteNonQuery ()
End if
objConn = Nothing
objConn.Close()
%>I believe 'password' is a keyword - but it is also your column name. Try
putting [ and ] around the column name.
Alsok you shouldn't just concatenate strings together given to you by the
user. They could easily put in malicious SQL for one of those values. I
would recommend using parameters.
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> Hello All,
> I am trying to insert a record in the MS Access DB and for some reason I
cannot get rid of error message,
> System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> And the line it shows in red is
> cmd.ExecuteNonQuery()
> I have pasted the entire code here. Can someone please give me some clue
as what could be wrong. The SQL string looks fine because I pasted the
resulting SQL in to MS Access. When I ran the Insert query, it properly
added the record in the Access DB.
> Thanks,
> Joe
>
> <%@. Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
> <%@. Import Namespace="System.Data.OleDb" %>
> <%@. Import Namespace="System.Data" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <%
> 'Open up a connection to Access database
> 'Using a DSN connection.
> Dim bolfFound, strUsername, bolAlreadyExists
> Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source='E:/Inetpub/databases/investors.mdb'")
> objConn.Open()
> 'check state
> If Session("strAdmin") <> "test" Then
> objConn.Close()
> objConn = Nothing
> Response.Write("<A HREF=index.aspx'>")
> Response.Write("Sorry, looks like your session timed out, please login
again.")
> Response.Write("</A>")
> Response.End()
> End If
> bolAlreadyExists = False
> Dim objDataReader as OledbDataReader
> Dim objCommand as New OledbCommand("Select * From Results", objConn)
> objDataReader = objCommand.ExecuteReader()
> Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
= 0) Then
> Response.Redirect("record_exists.aspx")
> bolAlreadyExists = True
> End If
> Loop
> objDataReader.Close()
> If Not bolAlreadyExists Then
> Dim Email, passwd, first_name, last_name, company, street_address,
address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
RemoteIP
> Email = Request.Form("Email")
> passwd = Request.Form("password")
> first_name = Request.Form("first_name")
> last_name = Request.Form("last_name")
> company = Request.Form("company")
> street_address = Request.Form("street_address")
> address2 = Request.Form("address2")
> city = Request.Form("city")
> prov = Request.Form("state")
> country = Request.Form("country")
> postal = Request.Form("postal")
> phone = Request.Form("phone")
> mobilePhone = Request.Form("mobile")
> AddDate = Now
> Inv = "Yes"
> RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> Dim MySQL as String
> MySQL = "INSERT INTO Results(email, password, first_name, last_name,
company, street_address, address2, city, state, country, postal, phone,
mobile, AddDate, Inv, RemoteIP)" & _
> " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"
> Dim cmd as New OleDBCommand (MySQL, objConn)
> cmd.ExecuteNonQuery ()
> End if
> objConn = Nothing
> objConn.Close()
> %>
>

Please help : System.Data.OleDb.OleDbException: Syntax error i

Yep..that got me a few times. Also Joe, be careful of using Date as a colum
n name as well, I know you didn't use it here but I had to find out the hard
way. It will cause the same type of error. The Jet Provider is picky abou
t those kinds of words
"Marina" wrote:

> I believe 'password' is a keyword - but it is also your column name. Try
> putting [ and ] around the column name.
> Alsok you shouldn't just concatenate strings together given to you by the
> user. They could easily put in malicious SQL for one of those values. I
> would recommend using parameters.
> "Joe" <Joe@dotnet.itags.org.discussions.microsoft.com> wrote in message
> news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@dotnet.itags.org.microsoft.com...
> cannot get rid of error message,
> as what could be wrong. The SQL string looks fine because I pasted the
> resulting SQL in to MS Access. When I ran the Insert query, it properly
> added the record in the Access DB.
> ResponseEncoding="iso-8859-1" %>
> "http://www.w3.org/TR/html4/loose.dtd">
> source='E:/Inetpub/databases/investors.mdb'")
> again.")
> = 0) Then
> address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investo
r,
> RemoteIP
> company, street_address, address2, city, state, country, postal, phone,
> mobile, AddDate, Inv, RemoteIP)" & _
> last_name & "', '" & company & "', '" & street_address & "', '" & address2
&
> "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '
"
> & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "'
,
> '" & RemoteIP & "')"
>
>Thanx guys after I put [] around password, AddDate and RemoteIP, the script
worked.
Joe
"Tampa .NET Koder" wrote:
> Yep..that got me a few times. Also Joe, be careful of using Date as a col
umn name as well, I know you didn't use it here but I had to find out the ha
rd way. It will cause the same type of error. The Jet Provider is picky ab
out those kinds of words
> "Marina" wrote:
>