sql server - C# insert in table doesn't work but select works perfect -


I work on a windows form C # application but I have some problems when I want to select everything from the table , Then that works right, but when I want to insert the data into my table, then there is no error and my application is "data entered in the database", but my table is empty

This is my The connection is:

  SqlConnection conexiune = new SqlConnection (@ "data source = (localized) B) \ v11.0; AttachDbFilename = | data directory | \ Banjo-D -date.mdf; Integrated Security = true ");  

This is my code:

  try {SqlCommand insert = new SqlCommand ("INSERT INTO [dbo]." [Tabel] ([ID], [ Noam], [pennem], [yorka] value (@ id, @ nme, @pranum, @ versta) ", consession); Insert.Parameters.AddWithValue ("@ ID", textBox1.Text); Insert.Parameters.AddWithValue ("@ nume", textBox2.Text); Insert. Parameter. AddWithValue ("Inspiration", Text Box 3. Text); Insert. Parameter. AddWithValue ("@ varsta", textBox4.Text); Conexiune.Open (); Insert.ExecuteReader (); MessageBox.Show ("Datele au fost introduse cu succes in baza de date!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information); } Hold {Messagebox.Show ("A Awat Loco Arore! Teng the Eggers Do not Know", "Arore!", Messbox Box, OK, Message Box, Compilation); } Finally {conexiune.Close (); This.Close (); }  

I am using Visual Studio 2013 and Microsoft SQL Server version 11.00.3000.

This A problem, at least:

  insert.ExecuteReader ();  

This is for queries, because you have reading data (as Steve has written, it still works - but

Call ExecuteNonQuery instead:

  insert.ExecuteNonQuery ();  

Additionally, I close the resources manually Instead of using the , I recommend using the statement. (You should also close SqlCommand .)

However, Steve The real problem is in the comments E was - you were copying a new copy of the database on every run, so I hope you will see an app inside an executable of the results included, but the next time you start the app But they will be lost.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -