Results 1 to 5 of 5

Thread: Records added in VS run mode are not showing up in the table

  1. #1
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2010
    Posts
    3
    Reputation
    0

    Records added in VS run mode are not showing up in the table

    I've gone through three books this week and still don't understand what's going on.

    I created a .mdf file in VS with two fields. I hit F5 and add records everything appears to work. I open the table in VS Server Explorer and it only shows the original record. I run the executable in the ../bin/debug folder and can access all the records. I go back to VS and hit F5 and I can access all the records. But when I view the table again in VS Server Explorer it still just shows one record.

    Saw an earlier post about setting the mdf file Copy to Output directory property to Copy if newer instead of Copy always but that didn't make any difference. I'm not using any designer generated datasets, etc. This is all in code. Here;re the globals and form load:

    Private m_cnTrainer As New SqlClient.SqlConnection
    Private m_daTrainer As SqlClient.SqlDataAdapter
    Private m_cbTrainer As SqlClient.SqlCommandBuilder
    Private m_dtTrainer As New DataTable
    Private m_rowPosition As Integer = 0


    Private Sub SwimTrainer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    m_cnTrainer.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\SwimTrainer.mdf;Integrated Security=True;User Instance=True"

    m_cnTrainer.Open()

    m_daTrainer = New SqlClient.SqlDataAdapter("SELECT * FROM tblWorkouts", m_cnTrainer)

    m_cbTrainer = New SqlClient.SqlCommandBuilder(m_daTrainer)

    m_daTrainer.Fill(m_dtTrainer)
    ShowCurrentRecord()
    End Sub

    Here's where I update the record:
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim drNewRow As DataRow = m_dtTrainer.NewRow

    drNewRow("Laps") = txtTotLaps.Text
    drNewRow("Distance") = txtTotDist.Text
    m_dtTrainer.Rows.Add(drNewRow)
    m_daTrainer.Update(m_dtTrainer)
    m_rowPosition = m_dtTrainer.Rows.Count - 1
    ShowCurrentRecord()
    End Sub

    Most of this is straight from Teach Yourself VB 2008 in 24 Hours but I'm having the same issue with a couple of tutorials this week.

    Any suggestions would be greatly appreciated.

  2. #2
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2010
    Posts
    3
    Reputation
    0
    PS I'm using Application.StartupPath in my connection string instead of hard coding the path. Do you suppose that's causing my problem?

  3. #3
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2010
    Posts
    3
    Reputation
    0
    Yes. Yes it was. Just need to remember to replace the path before I distribute it.

  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2862
    I'm not using any designer generated datasets, etc.
    Did you try them? It makes things easier. The default configuration (automatic) is to publish the included db file to the data directory and the connection string uses the |DataDirectory| dynamic variable.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  5. #5
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2006
    Posts
    7,052
    Reputation
    1773
    Read the DNU link in my signature

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •