Problem and Solutions
Error during SQL Update: "Incorrect Syntax Near '1'" [closed] in sql ?
By M.K. Verma · 4 May 2022
![Error during SQL Update: "Incorrect Syntax Near '1'" [closed] in sql ?](/_next/image?url=https%3A%2F%2Fserveapi.trimwebsolutions.com%2Fuploads%2Flegacy%2Fblog%2F16516772571651677257.jpg&w=3840&q=65)
You can debug and run your SQL query in SQL management studio to check what is wrong with your query.
try
{
if (dgvStockEntry.Rows.Count > 0)
{
if (MessageBox.Show("Are you sure you want to save this records?", stitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
for (int i = 0; i < dgvStockEntry.Rows.Count; i++)
{
cn.Open();
var quantity = dgvStockEntry.Rows[i].Cells[5].Value.ToString();
var pcode = dgvStockEntry.Rows[i].Cells[2].Value.ToString();
var sql = $"Update Products set Quantity = '{stockeEntry}' where Pcode like 'pcode'"
cm = new SqlCommand(, cn);
cm.ExecuteNonQuery();
cm = new SqlCommand("Update StockEntry set Quantity = Quantity '" + dgvStockEntry.Rows[i].Cells[5].Value.ToString() + ", Status = 'Done' where Id like '" + dgvStockEntry.Rows[i].Cells[0].Value.ToString() + "'", cn);
cm.ExecuteNonQuery();
cn.Close();
}
Clear();
LoadStockEntry();
}
}
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}