0

I'm probably blind or sm.

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Szymek\Desktop\Komunikator\Komunikator\Baza.mdf;Integrated Security=True");

private void button1_Click(object sender, EventArgs e)
{
    con.Open();
    String query = " INSERT INTO Uzytkownicy (imie, nazwisko, e-mail,login, haslo) VALUES ('"+ textBox1.Text + "','" +textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "')";

    SqlDataAdapter SDA = new SqlDataAdapter(query, con);
    SDA.SelectCommand.ExecuteNonQuery();

    con.Close();

    MessageBox.Show(" Zapisano ! ");

    this.Hide();
    Login move = new Login();
    move.ShowDialog();
}

Error at query I think:

System.Data.SqlClient.SqlException: „Incorrect syntax near '-'.”

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Szymon
  • 1
  • 2
    probably e-mail column name, try [e-mail] – BlackICE Mar 20 '18 at 14:50
  • Change "e-mail" to "[e-mail]" in the INSERT statement. – Simply Ged Mar 20 '18 at 14:50
  • 3
    Then make one of the textbox values `'` and see what happens. You need to use a parameterized insert. (You don't need that adapter at all btw, use an SqlCommand) – Alex K. Mar 20 '18 at 14:51
  • I suggest adding an 'sql-server' tag (I tried editing, but my edit was rejected due to the large amount of code in the question, even though I hadn't changed that). The SqlConnection, SqlDataAdapter and SqlCommand (suggested by AlexK) are all disposable, so should either be in a "using" block (which saves you from needing to call Close), or be explicitly disposed. Once you have tried Alex's suggestion, read up on [SQL Injection](https://stackoverflow.com/questions/601300/what-is-sql-injection). – Richardissimo Mar 20 '18 at 20:37

0 Answers0