Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This whole <em>User Instance and AttachDbFileName=</em> approach is flawed - at best! Visual Studio will be copying around the <code>.mdf</code> file (to your project's output directory where the app is run when inside Visual Studio), and <strong>most likely</strong>, your <code>INSERT</code> works just fine - but you're just looking at the <strong>wrong .mdf file</strong> in the end! </p> <p>If you want to stick with this approach, then try putting a breakpoint on the <code>myConnection.Close()</code> call - and then inspect the <code>.mdf</code> file (in your project's output directory) with SQL Server Mgmt Studio Express - I'm almost certain your data is there.</p> <p>The <strong>real solution</strong> in my opinion would be to </p> <ol> <li><p>install SQL Server Express (and you've already done that anyway)</p></li> <li><p>install SQL Server Management Studio Express</p></li> <li><p>create your database in <strong>SSMS Express</strong>, give it a logical name (e.g. <code>LiftLog</code>) </p></li> <li><p>connect to it using its logical <strong>database name</strong> (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:</p> <pre><code>Data Source=.\\SQLEXPRESS;Database=LiftLog;Integrated Security=True </code></pre> <p>and everything else is <strong>exactly</strong> the same as before...</p></li> </ol> <p>Also, please note: I would <strong>strongly recommend</strong> always using parametrized queries to a) avoid SQL injection attacks, and b) significantly improve performance in SQL Server.</p> <p>So instead of:</p> <pre><code>cmdInsert.CommandText = "INSERT INTO tblLog (Date, Time, Floor) VALUES (1011, 0011, 3)"; </code></pre> <p>you should use</p> <pre><code>cmdInsert.CommandText = "INSERT INTO tblLog (Date, Time, Floor) VALUES (@Date, @Time, @Floor)"; </code></pre> <p>and then define those parameters (<code>@Date, @Time, @Floor</code>) on your <code>SqlCommand</code> object and fill in their values that way.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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