Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Incorrect syntax near 'Quantity'.

C#
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
Updated 16-Dec-12 23:58pm
v2
Comments
__TR__ 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 17-Dec-12 6:00am    
error shows in the last line cmdh.executenonquery statement
ravuravu 17-Dec-12 6:03am    
i don,t know what is the real problem
jayantbramhankar 17-Dec-12 6:05am    
add comma(,) after each column in update query.
update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "' , ans so
ravuravu 17-Dec-12 6:09am    
yes u are correct

in Query you forgot to write comma separator in update fields
see, underlined portion in below code...
C#
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!
:)
 
Share this answer
 
Comments
ravuravu 17-Dec-12 6:30am    
thanks aarti mam
Aarti Meswania 17-Dec-12 6:51am    
welcome! :)
Glad to help you! :)
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();
 
Share this answer
 
Comments
ravuravu 17-Dec-12 6:31am    
thanks sir
[no name] 17-Dec-12 6:34am    
If you're satisfied with the given answer, Accept the Solution :)
-Krunal R.
ravuravu 17-Dec-12 6:47am    
ya i accepted and vote it
change your statement to:

C#
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:

C#
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity=" + nb + ", Price=" + TextBox3.Text + ", Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";


Regards
Pawan
 
Share this answer
 
Comments
ravuravu 17-Dec-12 6:32am    
thanks rai
dimpledevani 17-Dec-12 7:44am    
My 5+
Rai Pawan 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.
I think you are missing comma in the update SQL query. You should correct like this

SQL
string s11 = "update Item set Item='" + TextBox1.Text + "', Quantity='" + nb + "', Price='" + TextBox3.Text + "', Date='" + dt + "', Month='" + month + "' where Item='" + TextBox1.Text + "' ";
 
Share this answer
 
v2
Comments
ravuravu 17-Dec-12 6:32am    
thanks
you are missing , after the column name, please see below query

SQL
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900