Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help with SQL "INSERT INTO " syntax

Reply
Thread Tools

Help with SQL "INSERT INTO " syntax

 
 
ewpatton@gmail.com
Guest
Posts: n/a
 
      06-20-2007
Good day,


I've been trying to work with SQL and an Access database in order to
handle custom user profiles. I haven't had any trouble reading from my
database, but inserting new entries into it has been troublesome to
say the least.

My ASP.NET script is supposed to execute an INSERT INTO statement in
order to add a user to the database. Here is a sample:

INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
'0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')

This structure comes from http://www.w3schools.com/sql/sql_insert.asp

Everything seems valid, but ASP still throws an error stating that the
syntax of the statement is invalid. Could someone point out where the
'syntax' error is?

Evan

 
Reply With Quote
 
 
 
 
Srini
Guest
Posts: n/a
 
      06-20-2007
Try
INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
'0cc175b9c0f1b6a831c399e269772661',@ 'H:\CommConn\userdata\a.xml')

Notice the @ sign. "\" is an escape character. You have to use 2 '\'s if you
dont use the @ sign.

HTH

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Good day,
>
>
> I've been trying to work with SQL and an Access database in order to
> handle custom user profiles. I haven't had any trouble reading from my
> database, but inserting new entries into it has been troublesome to
> say the least.
>
> My ASP.NET script is supposed to execute an INSERT INTO statement in
> order to add a user to the database. Here is a sample:
>
> INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
> '0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')
>
> This structure comes from http://www.w3schools.com/sql/sql_insert.asp
>
> Everything seems valid, but ASP still throws an error stating that the
> syntax of the statement is invalid. Could someone point out where the
> 'syntax' error is?
>
> Evan
>



 
Reply With Quote
 
 
 
 
ewpatton@gmail.com
Guest
Posts: n/a
 
      06-21-2007
I was using Visual Basic, and did not believe that to be the problem.
I tried anyway, used the @ symbol. That didn't work, so I tried using
'\\' instead. Finally, I removed the last field altogether and had
just:

INSERT INTO LoginInfo (username, password) VALUES ('a',
'0cc175b9c0f1b6a831c399e269772661')

and the query still failed.

I'm totally lost now.

Evan

On Jun 20, 4:27 pm, "Srini" <(E-Mail Removed)> wrote:
> Try
> INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
> '0cc175b9c0f1b6a831c399e269772661',@ 'H:\CommConn\userdata\a.xml')
>
> Notice the @ sign. "\" is an escape character. You have to use 2 '\'s if you
> dont use the @ sign.
>
> HTH
>
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
> > Good day,

>
> > I've been trying to work with SQL and an Access database in order to
> > handle custom user profiles. I haven't had any trouble reading from my
> > database, but inserting new entries into it has been troublesome to
> > say the least.

>
> > My ASP.NET script is supposed to execute an INSERT INTO statement in
> > order to add a user to the database. Here is a sample:

>
> > INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
> > '0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')

>
> > This structure comes fromhttp://www.w3schools.com/sql/sql_insert.asp

>
> > Everything seems valid, but ASP still throws an error stating that the
> > syntax of the statement is invalid. Could someone point out where the
> > 'syntax' error is?

>
> > Evan



 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      06-21-2007
> Good day,
>
> I've been trying to work with SQL and an Access database in order to
> handle custom user profiles. I haven't had any trouble reading from my
> database, but inserting new entries into it has been troublesome to
> say the least.
>
> My ASP.NET script is supposed to execute an INSERT INTO statement in
> order to add a user to the database. Here is a sample:
>
> INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
> '0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')
>
> This structure comes from http://www.w3schools.com/sql/sql_insert.asp
>
> Everything seems valid, but ASP still throws an error stating that the
> syntax of the statement is invalid. Could someone point out where the
> 'syntax' error is?
>
> Evan
>


How are you executing this? C# or VB don't know anything about SQL commands.
You will have to use some sort of SqlCommand to send this sql-statement
to the database.

If this is not the problem, show some more code about how you are trying
to use it.

Hans Kestin


 
Reply With Quote
 
Larry Bud
Guest
Posts: n/a
 
      06-22-2007
On Jun 20, 4:12 pm, (E-Mail Removed) wrote:
> Good day,
>
> I've been trying to work with SQL and an Access database in order to
> handle custom user profiles. I haven't had any trouble reading from my
> database, but inserting new entries into it has been troublesome to
> say the least.
>
> My ASP.NET script is supposed to execute an INSERT INTO statement in
> order to add a user to the database. Here is a sample:
>
> INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
> '0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')
>
> This structure comes fromhttp://www.w3schools.com/sql/sql_insert.asp
>
> Everything seems valid, but ASP still throws an error stating that the
> syntax of the statement is invalid. Could someone point out where the
> 'syntax' error is?


A few things. First, are you building the insert string? If so, are
you positive it's building the way you think it is?

Always try the sql statement in query analyzer to see if your SQL
statement is valid, or if you're building a poor SQL statement.

 
Reply With Quote
 
Poldie
Guest
Posts: n/a
 
      06-22-2007
On Jun 21, 4:58 am, (E-Mail Removed) wrote:
> I was using Visual Basic, and did not believe that to be the problem.
> I tried anyway, used the @ symbol. That didn't work, so I tried using
> '\\' instead. Finally, I removed the last field altogether and had
> just:
>
> INSERT INTO LoginInfo (username, password) VALUES ('a',
> '0cc175b9c0f1b6a831c399e269772661')
>
> and the query still failed.
>
> I'm totally lost now.


What error are you getting? Have you tried putting username and/or
password into [square brackets] in case they are reserved words? Is
the username field large enough for the size of the data you're trying
to put into it? Is there any validation on the database which is
rejecting your data for violating constraints, primary key etc?

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      06-25-2007
It looks to me like it may be a data type exception, if the second column is
of SQL type uniqueidentifier, which is the same thing as a guid. The format
looks similar to the uniqueidentifier binary format, which would not have
single quotes around it. A uniqueidentifier value in a query should only
have single quotes around it when it is in the string format
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.


--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Larry Bud" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On Jun 20, 4:12 pm, (E-Mail Removed) wrote:
>> Good day,
>>
>> I've been trying to work with SQL and an Access database in order to
>> handle custom user profiles. I haven't had any trouble reading from my
>> database, but inserting new entries into it has been troublesome to
>> say the least.
>>
>> My ASP.NET script is supposed to execute an INSERT INTO statement in
>> order to add a user to the database. Here is a sample:
>>
>> INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
>> '0cc175b9c0f1b6a831c399e269772661', 'H:\CommConn\userdata\a.xml')
>>
>> This structure comes fromhttp://www.w3schools.com/sql/sql_insert.asp
>>
>> Everything seems valid, but ASP still throws an error stating that the
>> syntax of the statement is invalid. Could someone point out where the
>> 'syntax' error is?

>
> A few things. First, are you building the insert string? If so, are
> you positive it's building the way you think it is?
>
> Always try the sql statement in query analyzer to see if your SQL
> statement is valid, or if you're building a poor SQL statement.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL syntax error in INSERT INTO statement Nathan Sokalski ASP .Net 5 09-03-2010 02:12 AM
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Tools to extract data from SQL database and convert it into XML & insert XML data into SQL databases Harry Zoroc XML 1 07-12-2004 10:10 PM
Newbie SQL question: Break SQL into different SELECTs or keep as one Jules ASP General 6 07-15-2003 12:47 PM



Advertisments