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

TJDroid

New member
Joined
Jul 31, 2010
Messages
3
Programming Experience
10+
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.
 
PS I'm using Application.StartupPath in my connection string instead of hard coding the path. Do you suppose that's causing my problem?
 
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.
 
Back
Top