Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't Create The Same Table Twice in SQL Server
    text
    copied!<p>i have a C# Windows Form Application. I push a button it should create a Table and insert a value (int). I create the initial database as a Service-Database (Add New Item > Data > Service-Database).</p> <p>The code for the button is (output follows below it): </p> <pre><code>private void button1_Click(object sender, EventArgs e) { SqlConnection thisConnection = new SqlConnection(Properties.Settings.Default.Database1ConnectionString); SqlCommand nonqueryCommand = thisConnection.CreateCommand(); try { thisConnection.Open(); nonqueryCommand.CommandText = "CREATE TABLE MyTable1 (intColumn int)"; Console.WriteLine(nonqueryCommand.CommandText); Console.WriteLine("Number of Rows Affected is: {0}", nonqueryCommand.ExecuteNonQuery()); nonqueryCommand.CommandText = "INSERT INTO MyTable1 VALUES (99)"; Console.WriteLine(nonqueryCommand.CommandText); Console.WriteLine("Number of Rows Affected is: {0}", nonqueryCommand.ExecuteNonQuery()); } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } finally { thisConnection.Close(); // close connection Console.WriteLine("Connection Closed."); } } </code></pre> <blockquote> <p>OUTPUT: CREATE TABLE MyTable1 (intColumn int) Number of Rows Affected is: -1 INSERT INTO MyTable1 VALUES (99) Number of Rows Affected is: 1 Connection Closed.</p> </blockquote> <p>Nothing Shows up on Server Explorer Though No additional Tables even if I close it down and reconnect.</p> <p>If i push the button to make it issue the same again i get:</p> <pre><code>System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'MyTable1' in the database. </code></pre> <p>but still nothing on server explorer.</p>
 

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