RE: Newbie SQL Queston on INSERT

From: Chaim (Chaim_at_discussions.microsoft.com)
Date: 03/18/05


Date: Fri, 18 Mar 2005 10:13:05 -0800

You have to rewrite as follows:

     DBCmd.CommandText = "INSERT INTO Items (Title) VALUES (" & str & ")"

As written, it thinks the value to use is 'str'. Once it is in a string, VB
(nor anything else I can think of off the top of my head) does not
interpolate a variable; i.e., it doesn't treat the string as a variable
anymore but as a part of the string.

Whoops! I seem to remember Perl interpolating like that. But definitely not
VB.

"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



Relevant Pages

  • Re: Help:About Regex !!!
    ... If the HTML document is XHTML ... Dennis JD Myrén ... > My string will be not match this ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: conversion to c# from excel function help
    ... Dennis JD Myrén ... I found it when I was looking for a>>>function to convert numbers to excel like headers. ... Function Num2LetAs String ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Send EMail thru VB without User Intervention
    ... "Dennis" wrote in message ... > Const SW_SHOWNORMAL = 1 ... > ByVal lpOperation As String, ... > Private Sub Command1_Click ...
    (microsoft.public.vb.controls)
  • Re: =?ISO-8859-1?Q?Tibur=F3n_and_FastCode?=
    ... Functions defined with AnsiString as string type will have no problems ... Dennis Kjaer Christensen ...
    (borland.public.delphi.language.basm)
  • Re: Bestimmte Zeichenfolge aus einem String eremitteln (Regex)
    ... Dennis Nusser schrieb: ... > aus einem String eine Zeichenfolge ermitteln muss. ... > Leider habe ich keine Ahnung über Regex. ... > vorhanden das ich mich mit der Klasse auseinadergesetzt hätte. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)