I know very little about oledb so bare with me. I have a vb.net program with an access database connection. Everything seems to work fine except updating. It doesn't generate any error, but the updates are not made to the database. Here is some of my code:
Here is my Update Command Text:
"UPDATE nfcnorth SET Won = @Won, Loss = @Loss WHERE TeamName = @TeamName"
This is the startup module:
Module Module1
Public frm1 AsNew Form1
Public frmMod AsNew frmModify
Public frmSpl AsNew frmSplash
Public connNfcNorth AsNew OleDbConnection
Public daNfcNorth AsNew OleDbDataAdapter
Public dsNfcNorth AsNew DataSet
Public dtTable As DataTable
Public i As Int16
PublicSub Main()
'Application.Run(frmSpl)
Application.Run(frm1)
EndSub
EndModule
Here is the modify form:
Imports System.Data.oledb
'Imports System.Data.sqlclient
PublicClass frmModify
Inherits System.Windows.Forms.Form
PrivateSub frmModify_Activated(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Activated
lblTeam.Text = dtTable.Rows(i) _
("TeamName")
txtWins.Text = dtTable.Rows(i) _
("Won")
txtLoss.Text = dtTable.Rows(i) _
("Loss")
EndSub
PrivateSub txtWins_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtWins.LostFocus
daNfcNorth.UpdateCommand.Parameters.Clear()
Dim parmTeamName AsNew OleDbParameter("@TeamName", OleDbType.VarChar, 17)
parmTeamName.Value = lblTeam.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmTeamName)
Dim parmWon AsNew OleDbParameter("@Won", OleDbType.SmallInt, 2)
parmWon.Value = txtWins.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmWon)
Dim parmLoss AsNew OleDbParameter("@Loss", OleDbType.SmallInt, 2)
parmLoss.Value = txtLoss.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmLoss)
EndSub
PrivateSub txtLoss_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtLoss.LostFocus
daNfcNorth.UpdateCommand.Parameters.Clear()
Dim parmTeamName AsNew OleDbParameter("@TeamName", OleDbType.VarChar, 17)
parmTeamName.Value = lblTeam.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmTeamName)
Dim parmWon AsNew OleDbParameter("@Won", OleDbType.SmallInt)
parmWon.Value = txtWins.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmWon)
Dim parmLoss AsNew OleDbParameter("@Loss", OleDbType.SmallInt)
parmLoss.Value = txtLoss.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmLoss)
EndSub
PrivateSub btnUpdate_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnUpdate.Click
connNfcNorth.Open()
Try
daNfcNorth.UpdateCommand.ExecuteNonQuery()
Catch mex As OleDbException
MessageBox.Show(mex.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
EndTry
dsNfcNorth.Clear()
daNfcNorth.Fill(dsNfcNorth, "nfcnorth")
connNfcNorth.Close()
frm1.pct()
Me.Close()
EndSub
EndClass
Here is my Update Command Text:
"UPDATE nfcnorth SET Won = @Won, Loss = @Loss WHERE TeamName = @TeamName"
This is the startup module:
Module Module1
Public frm1 AsNew Form1
Public frmMod AsNew frmModify
Public frmSpl AsNew frmSplash
Public connNfcNorth AsNew OleDbConnection
Public daNfcNorth AsNew OleDbDataAdapter
Public dsNfcNorth AsNew DataSet
Public dtTable As DataTable
Public i As Int16
PublicSub Main()
'Application.Run(frmSpl)
Application.Run(frm1)
EndSub
EndModule
Here is the modify form:
Imports System.Data.oledb
'Imports System.Data.sqlclient
PublicClass frmModify
Inherits System.Windows.Forms.Form
PrivateSub frmModify_Activated(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Activated
lblTeam.Text = dtTable.Rows(i) _
("TeamName")
txtWins.Text = dtTable.Rows(i) _
("Won")
txtLoss.Text = dtTable.Rows(i) _
("Loss")
EndSub
PrivateSub txtWins_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtWins.LostFocus
daNfcNorth.UpdateCommand.Parameters.Clear()
Dim parmTeamName AsNew OleDbParameter("@TeamName", OleDbType.VarChar, 17)
parmTeamName.Value = lblTeam.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmTeamName)
Dim parmWon AsNew OleDbParameter("@Won", OleDbType.SmallInt, 2)
parmWon.Value = txtWins.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmWon)
Dim parmLoss AsNew OleDbParameter("@Loss", OleDbType.SmallInt, 2)
parmLoss.Value = txtLoss.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmLoss)
EndSub
PrivateSub txtLoss_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtLoss.LostFocus
daNfcNorth.UpdateCommand.Parameters.Clear()
Dim parmTeamName AsNew OleDbParameter("@TeamName", OleDbType.VarChar, 17)
parmTeamName.Value = lblTeam.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmTeamName)
Dim parmWon AsNew OleDbParameter("@Won", OleDbType.SmallInt)
parmWon.Value = txtWins.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmWon)
Dim parmLoss AsNew OleDbParameter("@Loss", OleDbType.SmallInt)
parmLoss.Value = txtLoss.Text
daNfcNorth.UpdateCommand.Parameters.Add(parmLoss)
EndSub
PrivateSub btnUpdate_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnUpdate.Click
connNfcNorth.Open()
Try
daNfcNorth.UpdateCommand.ExecuteNonQuery()
Catch mex As OleDbException
MessageBox.Show(mex.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
EndTry
dsNfcNorth.Clear()
daNfcNorth.Fill(dsNfcNorth, "nfcnorth")
connNfcNorth.Close()
frm1.pct()
Me.Close()
EndSub
EndClass
Last edited: