944,173 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 500
  • C# RSS
Nov 1st, 2009
0

sqlException--invalid expression

Expand Post »
Hello every one..
I have this exception while trying to execute an insert command into a simple sql database

C# Syntax (Toggle Plain Text)
  1. string myChar = charNameTextBox.Text;
  2.  
  3. string command = "insert into data (char,Entropy,Uniformity,stadev,smoothness,skewness,kurtosis) values(" + myChar + "," + entropy + "," + uniformity + "," + standardDeviation + "," + Smoothness + "," + skewness + "," + kurtosis + ")";
  4.  
  5. sqlComm = new SqlCommand(command, sqlConn);
  6. sqlComm.ExecuteNonQuery();

this is the exception ..occures against char with value myChar..
char is defined as nvarchar(MAX)
--------
The name "ب" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
--------

im sure i made a mistake but i can't discover where and i have not been working with database for a long time..

thanks in advance..
Reputation Points: 9
Solved Threads: 2
Light Poster
dima shawahneh is offline Offline
30 posts
since Sep 2009
Nov 1st, 2009
0
Re: sqlException--invalid expression
hello again
i think i was quick in submitting this thread

the problem was easy and solved by just adding single quotation
before and after the value myChar since it is a string

sorry for this mistake
my regards..
Reputation Points: 9
Solved Threads: 2
Light Poster
dima shawahneh is offline Offline
30 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Converting Java to C# GDI problem
Next Thread in C# Forum Timeline: problem in datagrid form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC