update access database

longway

Member
Joined
Mar 9, 2005
Messages
6
Programming Experience
Beginner
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

End
Module

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

End
Class

 
Last edited:
Formatting code makes it easier to read

It is too hard to read long sections of code like this and work out what they are doing. Put your code in
VB.NET:
 tags (click the # button on the advanced editor) and then indent it. That way we don't have to spend 10 minutes or so trying to decipher the code. You are by no means the only person who doesn't do this, but I have skipped over several questions I may have been able to help with because I wasn't prepared to decipher the long, hard-to-read code.
 
Back
Top