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.
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.