droose
Member
I need to update individual columns in selected rows of an access database in VB Express (net). The code I am using is listed below. It compiles but does not updata the data base. I have been able to find examples of everything about MS Access except, "How to update a record column from a variable rather than a data bound form element". Any help would be appreciated.
Thanks,
Dick Roose
[/SIZE]
Thanks,
Dick Roose
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' OLEDB Init
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strConnectionString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\ThePokerEdgeNet\Result.mdb"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objConn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbConnection(strConnectionString)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cb [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbCommandBuilder
[/SIZE][SIZE=2][COLOR=#008000]'Connect to provider (connectionstring above)
[/COLOR][/SIZE][SIZE=2]objConn.Open()
[/SIZE][SIZE=2][COLOR=#008000]' Data Source > Data Adapter > Data Set (create DataSet)
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]s = [/SIZE][SIZE=2][COLOR=#800000]"SELECT * FROM Results WHERE HandID = "[/COLOR][/SIZE][SIZE=2] & hid & [/SIZE][SIZE=2][COLOR=#800000]" and Suited = "[/COLOR][/SIZE][SIZE=2] & suited
da = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbDataAdapter(s, objConn)
cb = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbCommandBuilder(da)
DSet = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2])
da.Fill(DSet, [/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2])
d = DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Dealt"[/COLOR][/SIZE][SIZE=2]) + 1
DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Dealt"[/COLOR][/SIZE][SIZE=2]) = d
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] myBet <> 0 [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] WnLs <> 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]p = DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Played"[/COLOR][/SIZE][SIZE=2]) + 1
DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Played"[/COLOR][/SIZE][SIZE=2]) = p
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] WnLs > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]w = DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Won"[/COLOR][/SIZE][SIZE=2]) + 1
DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Won"[/COLOR][/SIZE][SIZE=2]) = w
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]per = System.Math.Round(w / p, 2)
DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).Rows(g_lngCurrentRow).Item([/SIZE][SIZE=2][COLOR=#800000]"Percent"[/COLOR][/SIZE][SIZE=2]) = per
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' Update the dataset
[/COLOR][/SIZE][SIZE=2]da.Update(DSet, [/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Catch
[/COLOR][/SIZE][SIZE=2]s = [/SIZE][SIZE=2][COLOR=#800000]"SELECT * FROM Results"
[/COLOR][/SIZE][SIZE=2]da = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbDataAdapter(s, objConn)
cb = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbCommandBuilder(da)
DSet = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2])
da.Fill(DSet, [/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Data.DataRow = DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_Dataset"[/COLOR][/SIZE][SIZE=2]).NewRow()
dr([/SIZE][SIZE=2][COLOR=#800000]"Cards"[/COLOR][/SIZE][SIZE=2]) = PDcards
dr([/SIZE][SIZE=2][COLOR=#800000]"HandID"[/COLOR][/SIZE][SIZE=2]) = hid
dr([/SIZE][SIZE=2][COLOR=#800000]"Suited"[/COLOR][/SIZE][SIZE=2]) = suited
dr([/SIZE][SIZE=2][COLOR=#800000]"OddsOW"[/COLOR][/SIZE][SIZE=2]) = OOW
dr([/SIZE][SIZE=2][COLOR=#800000]"Dealt"[/COLOR][/SIZE][SIZE=2]) = 1
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] myBet <> 0 [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] WnLs <> 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"Played"[/COLOR][/SIZE][SIZE=2]) = i
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] WnLs > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"Won"[/COLOR][/SIZE][SIZE=2]) = 1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]per = System.Math.Round(w / p, 2)
dr([/SIZE][SIZE=2][COLOR=#800000]"Percent"[/COLOR][/SIZE][SIZE=2]) = per
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"Played"[/COLOR][/SIZE][SIZE=2]) = 0
dr([/SIZE][SIZE=2][COLOR=#800000]"Won"[/COLOR][/SIZE][SIZE=2]) = 0
dr([/SIZE][SIZE=2][COLOR=#800000]"Percent"[/COLOR][/SIZE][SIZE=2]) = 0
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] istournament [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"CWinLost"[/COLOR][/SIZE][SIZE=2]) = WnLs
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] PlayMoney [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"PWinLost"[/COLOR][/SIZE][SIZE=2]) = WnLs
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dr([/SIZE][SIZE=2][COLOR=#800000]"$WinLost"[/COLOR][/SIZE][SIZE=2]) = WnLs
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]DSet.Tables([/SIZE][SIZE=2][COLOR=#800000]"MS_Access_DataSet"[/COLOR][/SIZE][SIZE=2]).Rows.Add(dr)
[/SIZE][SIZE=2][COLOR=#008000]'da.Update(DSet, "MS_Access_DataSet")
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]Cleanup()
objConn.Close()
Last edited: