SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 9th, 2004, 05:09 AM
jonnieay jonnieay is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 jonnieay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How do I insert an integer variable into an INSERT

I get the following error upon executing an INSERT.
(I am using vb.net)

The name 'x' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
.
My code looks like:

dim x as integer = 5

Dim cmd As New SqlCommand("INSERT INTO Restaurants (RestName, Street, TownID, Town, County, PostCode, Telephone, CuisineType, RankPriority, BriefDesc, PhotoUrl, MealDealDetails) VALUES('" & RestNameTxt.Text & "','" & StreetTxt.Text & "',x,'" & TownTxt.Text & "','" & CountyTxt.Text & "','" & PostCodeTxt.Text & "','" & TelephoneTxt.Text & "',5,5,'" & BriefDescTxt.Text & "','" & PhotoUrlTxt.Text & "','" & MealDealDetailsTxt.Text & "')", New SqlConnection(strConn))

cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()

Please can anyone help? Why can't I include a simple variable, x, in the Insert?

Thanks
Jonnieay

Reply With Quote
  #2  
Old April 9th, 2004, 05:37 AM
dip dip is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 dip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi

use this

****& StreetTxt.Text & "'," & x &" ', " & TownTxt.Text & "','" ****


i mean to say just replace & "',x,'" & with " '," & x &" ', "

let me know the result
dipit

Reply With Quote
  #3  
Old April 9th, 2004, 06:10 AM
jonnieay jonnieay is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 jonnieay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile You did it!

Thank you very much,

,"& x &",

It works! You've made my day.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > How do I insert an integer variable into an INSERT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT