Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Incorrect syntax near 'Quantity'.
 
DateTime date = DateTime.Parse(DateTime.Now.ToShortDateString());
string dt = date.ToString("MM/dd/yyyy");
string month = date.ToString("MMMM");
float mm=float.Parse(TextBox2.Text);
string df = "select Quantity from Item where Item='" + TextBox1.Text + "'";
SqlCommand dd = new SqlCommand(df,DbConnection.mCon);
SqlDataAdapter dg = new SqlDataAdapter(dd);
DataTable sd = new DataTable();
dg.Fill(sd);
if (sd.Rows.Count > 0)
{
  cc = float.Parse(sd.Rows[0][0].ToString());
}
float nb = cc + mm;
string s11 = "update Item set Item='" + TextBox1.Text + "' Quantity='" + nb + "' Price='" + TextBox3.Text + "' Date='" + dt + "' Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 SqlCommand cmdh = new SqlCommand(s11, DbConnection.mCon);
 cmdh.ExecuteNonQuery();
 
Table name Item
 
fieldname Quantity datatype float
Posted 17-Dec-12 0:57am
Edited 17-Dec-12 0:58am
__TR__28.9K
v2
Comments
__TR__ at 17-Dec-12 6:00am
   
Try executing the update statement generated by your code in SQL server. You might get an idea on what is wrong.
ravuravu at 17-Dec-12 6:00am
   
error shows in the last line cmdh.executenonquery statement
ravuravu at 17-Dec-12 6:03am
   
i don,t know what is the real problem
jayantbramhankar at 17-Dec-12 6:05am
   
add comma(,) after each column in update query.
update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "' , ans so
ravuravu at 17-Dec-12 6:09am
   
yes u are correct
ravuravu at 17-Dec-12 6:10am
   
thanks jayantbramhankar and __tr__ for helping me
Richard MacCutchan at 17-Dec-12 6:11am
   
You should not use string concatenation to create SQL commands; you are leaving your system open to SQL injection by spammers and viruses. Use proper parameterized queries.
ravuravu at 17-Dec-12 6:34am
   
how to use parameterised queries pls give me an example mr Richard MacCutchan.
i waiting for your example
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

in Query you forgot to write comma separator in update fields
see, underlined portion in below code...
string s11 = "update Item set Item='" + TextBox1.Text + "' , Quantity='" + nb + "' ,  Price='" + TextBox3.Text + "' ,  Date='" + dt + "' ,  Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 SqlCommand cmdh = new SqlCommand(s11, DbConnection.mCon);
 cmdh.ExecuteNonQuery();
Happy Coding!
Smile | :)
  Permalink  
Comments
ravuravu at 17-Dec-12 6:30am
   
thanks aarti mam
Aarti Meswania at 17-Dec-12 6:51am
   
welcome! :)
Glad to help you! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "', Price='" + TextBox3.Text + "', Date='" + dt + "' Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 SqlCommand cmdh = new SqlCommand(s11, DbConnection.mCon);
 cmdh.ExecuteNonQuery();
  Permalink  
Comments
ravuravu at 17-Dec-12 6:31am
   
thanks sir
Krunal Rohit at 17-Dec-12 6:34am
   
If you're satisfied with the given answer, Accept the Solution :)
-Krunal R.
ravuravu at 17-Dec-12 6:47am
   
ya i accepted and vote it
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

change your statement to:
 
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity=" + nb + ", Price='" + TextBox3.Text + "', Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 
note that a comma has been inserted between each column, apart from that I think that the quantity column is of type float so you should not be enclosing the value between single quotes, which has been removed in above query. Also check on what is the type of Price columns, since if it is also numeric/float/int type you will need to remove the single quotes from the value like this too:
 
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity=" + nb + ", Price=" + TextBox3.Text + ", Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 
Regards
Pawan
  Permalink  
Comments
ravuravu at 17-Dec-12 6:32am
   
thanks rai
dimpledevani at 17-Dec-12 7:44am
   
My 5+
Rai Pawan at 17-Dec-12 7:49am
   
Thanks! ravuravu just to guide you further please see tutorials on how to use sql command parameters since directly concatenating the values in sql command is not a good option.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think you are missing comma in the update SQL query. You should correct like this
 
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "', Price='" + TextBox3.Text + "', Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";
  Permalink  
v2
Comments
ravuravu at 17-Dec-12 6:32am
   
thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

you are missing , after the column name, please see below query
 
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "', Price='" + TextBox3.Text + "', Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 
Note: Use parameterised query for security issues.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 359
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100