RE: Newbie SQL Queston on INSERT
From: Chaim (Chaim_at_discussions.microsoft.com)
Date: 03/18/05
- Next message: Chaim: "RE: Newbie SQL Queston on INSERT"
- Previous message: Dennis: "Newbie SQL Queston on INSERT"
- In reply to: Dennis: "Newbie SQL Queston on INSERT"
- Next in thread: Chaim: "RE: Newbie SQL Queston on INSERT"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Chaim: "RE: Newbie SQL Queston on INSERT"
- Previous message: Dennis: "Newbie SQL Queston on INSERT"
- In reply to: Dennis: "Newbie SQL Queston on INSERT"
- Next in thread: Chaim: "RE: Newbie SQL Queston on INSERT"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|