vb.net | Update DB with OleDB
Posted
by liron
on Stack Overflow
See other posts from Stack Overflow
or by liron
Published on 2010-04-02T19:42:19Z
Indexed on
2010/04/02
19:43 UTC
Read the original article
Hit count: 423
i wrote a module of a connection to DB with OleDB and the 'sub UpdateClients' doesn't work, the DB don't update.
what's missing or wrong?
Module mdlDB
Const CONNECTION_STRING As String = _
"provider= Microsoft.Jet.OleDB.4.0;Data Source=DbHalf.mdb;mode= Share Deny None"
Dim daClient As New OleDb.OleDbDataAdapter
Dim dsClient As New DataSet
Dim cmClient As CurrencyManager
Public Sub OpenClients(ByVal txtId, ByVal txtName, ByVal BindingContext)
Dim Con As New OleDb.OleDbConnection(CONNECTION_STRING)
Dim sqlClient As New OleDb.OleDbCommand
Con.Open()
sqlClient.CommandText = "SELECT*"
sqlClient.CommandText += "FROM tblClubClient"
sqlClient.Connection = Con
daClient.SelectCommand = sqlClient
dsClient.Clear()
daClient.Fill(dsClient, "CLUB_CLIENT")
cmClient = BindingContext(dsClient, "CLUB_CLIENT")
cmClient.Position = 0
txtId.DataBindings.Add("text", dsClient, "CLUB_CLIENT.ClntId")
txtName.DataBindings.Add("text", dsClient, "CLUB_CLIENT.ClntName")
Con.Close()
End Sub
Public Sub UpdateClients(ByVal txtId, ByVal txtName, ByVal BindingContext)
Dim cb As New OleDb.OleDbCommandBuilder(daClient)
cmClient = BindingContext(dsClient, "CLUB_CLIENT")
dsClient.Tables("CLUB_CLIENT").Rows(cmClient.Position).Item("ClntId") = txtId.Text
dsClient.Tables("CLUB_CLIENT").Rows(cmClient.Position).Item("ClntName") = txtName.Text
daClient.Update(dsClient, "CLUB_CLIENT")
End Sub
End Module
© Stack Overflow or respective owner