Note that there are some explanatory texts on larger screens.

plurals
  1. POUPDATE Query : Incorrect Syntax (Edited)
    primarykey
    data
    text
    <p>I have a button which saves the contents edited in datagridview in my UI design. Here is the code for that Button_Save:</p> <pre><code> public void btnUpdate_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection("server=Test; Integrated Security=true; Database=Test;"); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); var sql = new StringBuilder(); sql.AppendLine("UPDATE dbo.JobStatus"); sql.AppendLine("Set ShipTrackingNumber = @ShipTrackingNumber"); sql.AppendLine(", ShipMethodTransmitted = @ShipMethodTransmitted"); sql.AppendLine(", DateShipTransmitProcessed = @DateShipTransmitProcessed"); sql.AppendLine(", ShipmentProcessedBy = @ShipmentProcessedBy"); sql.AppendLine(", Critical = @Critical"); sql.AppendLine(", ShipTransmitStatus = @ShipTransmitStatus"); sql.AppendLine("Where jobtableId = @jobTableId"); cmd.Connection = sqlConnection1; cmd.CommandText = sql.ToString(); cmd.Parameters.AddWithValue("@TrackingNumber", row.Cells[7].FormattedValue); cmd.Parameters.AddWithValue("@ShipMethodTransmitted", row.Cells[8].FormattedValue); cmd.Parameters.AddWithValue("@DateShipTransmitProcessed", row.Cells[9].FormattedValue); cmd.Parameters.AddWithValue("@ShipmentProcessedBy", row.Cells[10].FormattedValue); cmd.Parameters.AddWithValue("@Critical", row.Cells[11].FormattedValue); cmd.Parameters.AddWithValue("@ShipTransmitStatus", row.Cells[13].FormattedValue); cmd.Parameters.AddWithValue("@jobTableId", row.Cells[5].FormattedValue); sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close(); </code></pre> <p>What I am getting error is that: "Must declare the scalar variable "@ShipTrackingNumber". I dont want to put ShipTrackingNumber from the code. Instead I want to fetch it from the UI. </p> <p>What I am doing wrong here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload