sqlException--invalid expression

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2009
Posts: 26
Reputation: dima shawahneh is an unknown quantity at this point 
Solved Threads: 2
dima shawahneh dima shawahneh is offline Offline
Light Poster

sqlException--invalid expression

 
0
  #1
Nov 1st, 2009
Hello every one..
I have this exception while trying to execute an insert command into a simple sql database

  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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 26
Reputation: dima shawahneh is an unknown quantity at this point 
Solved Threads: 2
dima shawahneh dima shawahneh is offline Offline
Light Poster
 
0
  #2
Nov 1st, 2009
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..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum


Views: 196 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC