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
 General SQL Server Forums
 New to SQL Server Programming
 insert string into varchar column?

Author  Topic 

KarinElvira
Starting Member

47 Posts

Posted - 2010-08-18 : 08:17:09
I'm trying to insert an email address into a varchar column (I read somewhere that varchar is suitable for email addresses). The email address is fetched from a textbox as a string. The error message is:

The name "[any email address]" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

I suppose I need to convert the string to varchar, how do I do that? Links to tutorials and/or code examples would be great!

Thankful for any help! I'm not including any code right now because I honestly don't think it will be of any use since I'm guessing my way ahead... :)

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2010-08-18 : 08:21:15
post your insert statement

--------------------
keeping it simple...
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-08-18 : 08:25:24
*ducking*

"INSERT INTO NewsletterRecipients (email) VALUES (" + TextBoxEmailNewsletter.Text + ")";

I understand this is incorrect but I just can't find any info I understand on how to do this. Convert.To[something] i guess...
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-18 : 09:52:43
quote:
Originally posted by KarinElvira

*ducking*

"INSERT INTO NewsletterRecipients (email) VALUES (" + TextBoxEmailNewsletter.Text + ")";

I understand this is incorrect but I just can't find any info I understand on how to do this. Convert.To[something] i guess...


You are missing the single quotes while inserting the data
"INSERT INTO NewsletterRecipients (email) VALUES ('" + TextBoxEmailNewsletter.Text + "')"

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-18 : 11:14:39
It is better to make use of command object with parameters

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-08-18 : 14:28:17
quote:
Originally posted by vijayisonly


You are missing the single quotes while inserting the data
"INSERT INTO NewsletterRecipients (email) VALUES ('" + TextBoxEmailNewsletter.Text + "')"


[/quote]
As simple as that, huh! Thanks, I'll remember to check out when to use different kinds of quotes and how to combine them.
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-08-18 : 14:29:03
quote:
Originally posted by madhivanan

It is better to make use of command object with parameters

Madhivanan

Failing to plan is Planning to fail


I will check out parameters.
Go to Top of Page
   

- Advertisement -