Jaguar3311 Posted December 8, 2004 Posted December 8, 2004 Hi, I am having trouble inserting Strings and Chars into my database through variables. If I put a number into the variable it will insert, if it is any type of character or string of characters, it will not. In this example, the variable theOption and number would insert into the database fine. However, theAnswer (which includes a string of chars in it) will not insert. In the database, surveyID is numeric, questionID is an int, optionID is a varchar (length 2) and answer is a varchar (length 5000). Any help would be great thnx. int number = 12; String theOption = "1"; String theAnswer = "aba"; myCmd.CommandText = "INSERT INTO response(surveyID, questionID, optionID, answer) VALUES(123," + number + "," + theOption + "," + theAnswer + ")"; I am running VS .net 2003, my DB is SQL Server 2000, and the language is C#. Quote
Administrators PlausiblyDamp Posted December 8, 2004 Administrators Posted December 8, 2004 Strings need to be enclosed in single quotes, or even better use a stored procedure with parameters. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.