Help with SQL "INSERT INTO " syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ewpatton@gmail.com

    Help with SQL "INSERT INTO " syntax

    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',
    '0cc175b9c0f1b6 a831c399e269772 661', 'H:\CommConn\us erdata\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

  • Srini

    #2
    Re: Help with SQL "INSERT INTO " syntax

    Try
    INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
    '0cc175b9c0f1b6 a831c399e269772 661',@ 'H:\CommConn\us erdata\a.xml')

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

    HTH

    <ewpatton@gmail .comwrote in message
    news:1182370323 .852291.236010@ g4g2000hsf.goog legroups.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',
    '0cc175b9c0f1b6 a831c399e269772 661', 'H:\CommConn\us erdata\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
    >

    Comment

    • ewpatton@gmail.com

      #3
      Re: Help with SQL &quot;INSERT INTO &quot; syntax

      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',
      '0cc175b9c0f1b6 a831c399e269772 661')

      and the query still failed.

      I'm totally lost now.

      Evan

      On Jun 20, 4:27 pm, "Srini" <ls_re...@hotma il.comwrote:
      Try
      INSERT INTO LoginInfo (username, password, datafile) VALUES ('a',
      '0cc175b9c0f1b6 a831c399e269772 661',@ 'H:\CommConn\us erdata\a.xml')
      >
      Notice the @ sign. "\" is an escape character. You have to use 2 '\'s if you
      dont use the @ sign.
      >
      HTH
      >
      <ewpat...@gmail .comwrote in message
      >
      news:1182370323 .852291.236010@ g4g2000hsf.goog legroups.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',
      '0cc175b9c0f1b6 a831c399e269772 661', 'H:\CommConn\us erdata\a.xml')
      >
      This structure comes fromhttp://www.w3schools.c om/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

      Comment

      • Hans Kesting

        #4
        Re: Help with SQL &quot;INSERT INTO &quot; syntax

        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',
        '0cc175b9c0f1b6 a831c399e269772 661', 'H:\CommConn\us erdata\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 Kesting


        Comment

        • Larry Bud

          #5
          Re: Help with SQL &quot;INSERT INTO &quot; syntax

          On Jun 20, 4:12 pm, ewpat...@gmail. com 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',
          '0cc175b9c0f1b6 a831c399e269772 661', 'H:\CommConn\us erdata\a.xml')
          >
          This structure comes fromhttp://www.w3schools.c om/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.

          Comment

          • Poldie

            #6
            Re: Help with SQL &quot;INSERT INTO &quot; syntax

            On Jun 21, 4:58 am, ewpat...@gmail. com 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',
            '0cc175b9c0f1b6 a831c399e269772 661')
            >
            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?

            Comment

            • Kevin Spencer

              #7
              Re: Help with SQL &quot;INSERT INTO &quot; syntax

              It looks to me like it may be a data type exception, if the second column is
              of SQL type uniqueidentifie r, which is the same thing as a guid. The format
              looks similar to the uniqueidentifie r binary format, which would not have
              single quotes around it. A uniqueidentifie r 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:


              "Larry Bud" <larrybud2002@y ahoo.comwrote in message
              news:1182541502 .244895.127370@ o11g2000prd.goo glegroups.com.. .
              On Jun 20, 4:12 pm, ewpat...@gmail. com 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',
              >'0cc175b9c0f1b 6a831c399e26977 2661', 'H:\CommConn\us erdata\a.xml')
              >>
              >This structure comes fromhttp://www.w3schools.c om/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.
              >

              Comment

              Working...