Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Command Executenonquery - Syntax Error
    primarykey
    data
    text
    <p>I tried to update some data in C# I got </p> <blockquote> <p>"Incorrect syntax near ')'." in line "da.UpdateCommand.ExecuteNonQuery();".</p> </blockquote> <p>I browsed code a lot of time, and I can't see error anymore. So in my opinion should be OK, but isn't. Could you look at below code? </p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace klinika { public partial class frModWla : Form { DataSet ds = new DataSet(); SqlConnection cs = new SqlConnection("Data Source=.\\SQLEXPRESS; Initial Catalog=Klinika; Integrated security=TRUE"); SqlDataAdapter da = new SqlDataAdapter(); BindingSource bs = new BindingSource(); public frModWla() { InitializeComponent(); } private void btnWyswietl_Click(object sender, EventArgs e) { bindingClear(); da.SelectCommand = new SqlCommand("SELECT * FROM tbWlasciciel", cs); ds.Clear(); da.Fill(ds); dg.DataSource = ds.Tables[0]; bs.DataSource = ds.Tables[0]; tbxImie.DataBindings.Add(new Binding("Text", bs, "Imie")); tbxNazwisko.DataBindings.Add(new Binding("Text", bs, "Nazwisko")); tbxMiejscowosc.DataBindings.Add(new Binding("Text", bs, "Miejscowosc")); tbxKodPocztowy.DataBindings.Add(new Binding("Text", bs, "Kod_pocztowy")); tbxAdres.DataBindings.Add(new Binding("Text", bs, "Adres")); tbxTelefon.DataBindings.Add(new Binding("Text", bs, "Telefon")); tbxEmail.DataBindings.Add(new Binding("Text", bs, "Email")); rekord(); } private void bindingClear() { tbxImie.DataBindings.Clear(); tbxNazwisko.DataBindings.Clear(); tbxMiejscowosc.DataBindings.Clear(); tbxKodPocztowy.DataBindings.Clear(); tbxAdres.DataBindings.Clear(); tbxTelefon.DataBindings.Clear(); tbxEmail.DataBindings.Clear(); } private void btnPoprzedni_Click(object sender, EventArgs e) { bs.MovePrevious(); dgUpdate(); rekord(); } private void btnNastepny_Click(object sender, EventArgs e) { bs.MoveNext(); dgUpdate(); rekord(); } private void btnPierwszy_Click(object sender, EventArgs e) { bs.MoveFirst(); dgUpdate(); rekord(); } private void btnOstatni_Click(object sender, EventArgs e) { bs.MoveLast(); dgUpdate(); rekord(); } private void dgUpdate() { dg.ClearSelection(); dg.Rows[bs.Position].Selected = true; rekord(); } private void rekord() { lblRecords.Text = "Rekord " + bs.Position + " z " + (bs.Count - 1); } private void btnUaktualnij_Click(object sender, EventArgs e) { da.UpdateCommand = new SqlCommand("UPDATE tbWlasciciel SET NAZWISKO = @NAZWISKO, IMIE = @IMIE, MIEJSCOWOSC = @MIEJSCOWOSC, KOD_POCZTOWY = @KOD_POCZTOWY, ADRES = @ADRES, TELEFON = @TELEFON, EMAIL = @EMAIL WHERE ID_WLASCICIELA = @ID_WLASCICIELA)", cs); da.UpdateCommand.Parameters.Add("@IMIE", SqlDbType.VarChar).Value = tbxImie.Text; da.UpdateCommand.Parameters.Add("@NAZWISKO", SqlDbType.VarChar).Value = tbxNazwisko.Text; da.UpdateCommand.Parameters.Add("@MIEJSCOWOSC", SqlDbType.VarChar).Value = tbxMiejscowosc.Text; da.UpdateCommand.Parameters.Add("@KOD_POCZTOWY", SqlDbType.VarChar).Value = tbxKodPocztowy.Text; da.UpdateCommand.Parameters.Add("@ADRES", SqlDbType.VarChar).Value = tbxAdres.Text; da.UpdateCommand.Parameters.Add("@TELEFON", SqlDbType.VarChar).Value = tbxTelefon.Text; da.UpdateCommand.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value = tbxEmail.Text; da.UpdateCommand.Parameters.Add("@ID_WLASCICIELA", SqlDbType.Int).Value = ds.Tables[0].Rows[bs.Position][0]; cs.Open(); da.UpdateCommand.ExecuteNonQuery(); MessageBox.Show("Dane w bazie danych zostały zaktualizowane!", "Aktualizacja danych"); cs.Close(); } } } </code></pre>
    singulars
    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.
 

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