Re: Newbie SQL Queston on INSERT

From: Mark J. McGinty (mmcginty_at_spamfromyou.com)
Date: 03/18/05

  • Next message: Dennis: "Re: Newbie SQL Queston on INSERT"
    Date: Fri, 18 Mar 2005 11:11:02 -0800
    
    

    It's also a little surprising that he ends up with 'str' as the field's
    value, something must be interpolating it before passing it to SQL,
    otherwise it should throw an error. In QA I get:

    The name 'str' is not permitted in this context. Only constants,
    expressions, or variables allowed here. Column names are not permitted.

    Further, STR is a built-in function, but without parens apparently that does
    not come into play.

    -Mark

    "Chaim" <Chaim@discussions.microsoft.com> wrote in message
    news:98FF29E5-8D05-4E9A-8CA0-17BD7FCF340C@microsoft.com...
    > I'm also not sure about the 'new' in your initialization of str. It seems
    > that it should probably just read:
    > dim str as string = "First Record"
    >
    > But that's just my guess from reading the grammar and following the links
    > in
    > the VB.NET Language Spec. The 'New' seems to be used to create a new
    > object
    > reference. You aren't creating a new object, just assigning a literal.
    >
    > "Dennis" wrote:
    >
    >> I am trying to get my SQL statement correct for inserting data into a
    >> column
    >> using a string variable in VB.Net. Following is my code:
    >>
    >> dim str as string = new "First Record"
    >> DBCmd.CommandText = "INSERT INTO Items (Title) VALUES (str)"
    >> DBCmd.ExecuteNonQuery()
    >>
    >> The value it puts into the Title Field is "str" not "First Record". What
    >> am
    >> I doing wrong?
    >> --
    >> Dennis in Houston


  • Next message: Dennis: "Re: Newbie SQL Queston on INSERT"

    Relevant Pages

    • Re: SQL Job question
      ... EXEC master..xp_cmdshell @str ... Andrew J. Kelly SQL MVP ... Backup', STATS = 10, DESCRIPTION = N'WinFM DB Full Backup' ...
      (microsoft.public.sqlserver.setup)
    • Re: SQL Job question
      ... Can you execute this from QA and have it work? ... Andrew J. Kelly SQL MVP ... I'm trying to setup an automated way to backup a database, ... DECLARE @str nvarchar ...
      (microsoft.public.sqlserver.setup)
    • Re: SQL Job question
      ... SA and with Windows authentication. ... Andrew J. Kelly SQL MVP ... I'm trying to setup an automated way to backup a database, ... DECLARE @str nvarchar ...
      (microsoft.public.sqlserver.setup)
    • Re: SQL Syntax error in sp and ud function
      ... > EXEC (@str) ... > Tibor Karaszi, SQL Server MVP ... >> CREATE PROCEDURE Coder ...
      (microsoft.public.sqlserver.programming)
    • Re: SQL Job question
      ... it appears they are geared towards running the script ... If so then my guess would be the account that SQL Agent or the proxy ... DECLARE @str nvarchar ... Backup', STATS = 10, DESCRIPTION = N'WinFM DB Full Backup' ...
      (microsoft.public.sqlserver.setup)