0

Hello guys I have got this code:

SqlCommand scom = new SqlCommand(
                                "INSERT INTO klient(name,surname) 
                                values(@kname,@ksurname)", 
                                conn);

scom.Parameters.AddWithValue("@kname", kname.Text);
scom.Parameters.AddWithValue("@ksurname", ksurname.Text);
conn.Open();
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM klient", spojeni);
SDA.Fill(dt);
conn.Close();

It should insert data from textboxes: kname, ksurname, but it closes the form without showing them in MS SQL table klient

1
  • 1
    You simply haven't executed prikaz Commented Jul 10, 2013 at 11:08

3 Answers 3

6

Missing the ExecuteNonQuery call

SqlCommand prikaz = new SqlCommand("INSERT INTO klient(name,surname) values(@kname,@ksurname)", spojeni);

prikaz.Parameters.AddWithValue("@kname", kname.Text);
prikaz.Parameters.AddWithValue("@ksurname", ksurname.Text);
spojeni.Open();
prikaz.ExecuteNonQuery();
......

A command should be executed to update the database...

Sign up to request clarification or add additional context in comments.

Comments

3

You haven't executed the command.

prikaz.ExecuteNonQuery();

Comments

3

The above stated problem is due to the missing executenonquery() statement, add this statement in your code

spojeni.Open();
prikaz.ExecuteNonQuery();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.