Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Insert into syntax

Author  Topic 

caterpillar
Starting Member

9 Posts

Posted - 2006-09-21 : 10:35:15
Hi,

I have to insert fields in a table. I am using VB.net & SQL Server database.
The code is:
Dim var1 As Int32 = Me.classname.UserID
Dim strSQLD As String = "Insert into table1 (userid) values (var1)"

userid is of type int
While debugging, i can see that variable var1 is getting the integer value.

This is giving Syntax Error:The name 'var1' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Any help is appreciated.

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-21 : 10:45:30
Why don't you use stored procedures?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 10:58:28
If you PRINT strSQLD, what do you see?
Doing this might give you a hint of how to solve your problem.

The solution is using parameters and stored procedures, but you aren't familiar to that, concatenation might be of use.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

caterpillar
Starting Member

9 Posts

Posted - 2006-09-21 : 11:37:05
Hi Guys,

Thanks for your replies. I got it like this:

Dim strSQLI As String = "Insert into table1 (userid) values (" & Me.Classname.UserID)"

Regards
Monica
Go to Top of Page
   

- Advertisement -