•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 427,462 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,620 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 5967 | Replies: 4 | Solved
![]() |
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have to insert fields in a table. I am using VB.net & SQL Server database.
The code is:
Dim userid As Int32 = Me.classname.UserID
Dim strSQLD As String = "Insert into table1 (userid) values (Me.classname.UserID)"
userid is of type int
While debugging, i can see that variable userid is getting the interegr value.
This is giving Syntax Error:The name 'userid' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
Any help is appreciated.
Regards
Monica
I have to insert fields in a table. I am using VB.net & SQL Server database.
The code is:
Dim userid As Int32 = Me.classname.UserID
Dim strSQLD As String = "Insert into table1 (userid) values (Me.classname.UserID)"
userid is of type int
While debugging, i can see that variable userid is getting the interegr value.
This is giving Syntax Error:The name 'userid' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
Any help is appreciated.
Regards
Monica
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
You're not substituting Me.classname.UserID as a variable. You're passing it in the code as a value itself.
I have tried this also:
Dim var1 As Int32 = Me.classname.UserID
Dim strSQLD As String = "Insert into table1 (userid) values (var1)"
But it did not work. It is giving this error:
The name 'var1' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
Any solutions?
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
Dim userid As Int32 = Me.classname.UserID
Dim strSQLD As String = "Insert into table1 (userid) values (" & Me.classname.UserID & ")"You need to concatenate the value into the string, I beleive VB.Net will implicitly convert UserID to a string, otherwise convert/cast it first.
UserId by the way is a keyword in TSQL so if you have to use it in any MS SQL strings always put [] around it [UserId] so it is evaluated literally by MSSQL's query engine and optimizer.
Last edited by hollystyles : Sep 21st, 2006 at 10:37 am.
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Dim userid As Int32 = Me.classname.UserID Dim strSQLD As String = "Insert into table1 (userid) values (" & Me.classname.UserID & ")"
You need to concatenate the value into the string, I beleive VB.Net will implicitly convert UserID to a string, otherwise convert/cast it first.
UserId by the way is a keyword in TSQL so if you have to use it in any MS SQL strings always put [] around it [UserId] so it is evaluated literally by MSSQL's query engine and optimizer.
Thanks a lot !
It worked.
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Need help with the syntax problem (PHP)
- problem with commondialog (Visual Basic 4 / 5 / 6)
- amigious problem with fstream (C++)
- Problem with moving integers to a single formatted string (C)
Other Threads in the MS SQL Forum
- Previous Thread: SQL date problem
- Next Thread: Week function help



Linear Mode