Updating and saving on database
Updating and saving on database
Updating and saving on database
Updating and saving on database
Updating and saving on database
Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database
Updating and saving on database Updating and saving on database
Updating and saving on database
Go Back  Xtreme Visual Basic Talk > > > Updating and saving on database


Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2016, 11:48 AM
ktbjx ktbjx is offline
Newcomer
 
Join Date: May 2015
Posts: 1
Default Updating and saving on database


please help me is my code wrong????
i cant edit or update on my database
heres my Module:

Code:
Option Explicit
Public EmpNumb As String
Public EmpPosition As String
Public conn As New ADODB.Connection
Public RS As New ADODB.Recordset
Public cmd As New ADODB.Command
Public SQL As String
Public EmpNo As String

Public Sub connectDB()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\Database\Logsheet.mdb;User ID=admin;Persist Security 

Info=False;JET OLEDB:Database Password=drenzl"
conn.Open
With RS
    .ActiveConnection = conn
    .Open SQL, conn, 3, 3
End With
End Sub

Public Sub connOpen()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\Database\Logsheet.mdb;User ID=admin;Persist Security 

Info=False;JET OLEDB:Database Password=drenzl"
conn.Open

With cmd
    .ActiveConnection = conn
    .CommandType = adCmdText
    .CommandText = SQL
    Set RS = .Execute
End With
End Sub

Public Sub connClose()
' Close Database Connection
Set conn = Nothing
Set RS = Nothing
End

heere is where the problem is!!
on Private Sub cmdupdate_Click()


Code:
Option Explicit
Dim tlabel, tstatus, twork As String
Dim tchapa As Integer

Private Sub cmdaddnew_Click()
Dim MsgBoxResult
MsgBoxResult = MsgBox("You are about to add NEW DATA. Are you sure about this?", vbYesNo, "Wait lang!")
If MsgBoxResult = 6 Then
    If txtchapa.Text = "" Or txtlabel.Text = "" Or Combo1.Text = "" Or Combo2.Text = "" Then
    MsgBox "Some Fields are EMPTY. Unable to save!"
    Else
    SQL = "SELECT * FROM Workload"
    connectDB
    With RS
        .MoveLast
        .AddNew
        .Fields!chapa = txtchapa.Text
        .Fields!trabaho = txtlabel.Text
        .Fields!Work = Combo1.Text
        .Fields!Remarks = Combo2.Text
        .Fields!Date_made = Format(Now, "mm/dd/yyyy")
        .Update
    End With
    connClose
Unload Me
'frmworkload.connworkload
frmworkload.Show
End If
Else
End If
End Sub

Private Sub cmdcancel_Click()
connClose
Unload Me
End Sub

Private Sub cmdupdate_Click()

'On Error Resume Next
'SQL = "SELECT * FROM Workload WHERE trabaho = '" & tlabel & _
"'" And chapa = "'" & tchapa & "'" And Remarks = "'" & tstatus & "'"
SQL = "SELECT * FROM Workload WHERE Workload.trabaho = '" _
& tlabel & "' and Workload.chapa = '" & tchapa & "' and Workload.work = '" & _
twork & "' and Workload.Remarks = '" & tstatus & "'"
connectDB

With RS

        .Fields!chapa = txtchapa.Text
        .Fields!trabaho = txtlabel.Text
        .Fields!Work = Combo1.Text
        .Fields!Remarks = Combo2.Text
        .Fields!Date_made = Format(Now, "mm/dd/yyyy")
        .Update
   
End With
connClose
'frmworkload.connworkload
Unload Me
frmworkload.Show
End Sub

Private Sub Form_Load()
connClose
Display_work

tchapa = Val(txtchapa.Text)
tlabel = txtlabel.Text
tstatus = Combo2.Text
twork = Combo1.Text
End Sub
Sub Display_work()
Combo1.Clear

SQL = "SELECT * FROM works"
connectDB
With RS
    .MoveFirst
    While Not .EOF
        Combo1.AddItem .Fields!Works
        .MoveNext
    Wend
End With
connClose
End Sub

Last edited by Kluz; 04-21-2016 at 09:52 PM. Reason: wrap text to improve readability
Reply With Quote
  #2  
Old 05-26-2016, 11:26 PM
Dennis DVR's Avatar
Dennis DVRUpdating and saving on database Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

What is the primary key of your table? Your query should only return 1 record since you are only updating single record and you should not include the primary key field(s) in your update. If you are saving a child records then you should first delete all the child records then issue an insert.

I suggest you ditch the recordset object and directly issue an action query using the Execute command of your connection object.
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
Reply

Tags
public, sql, connclose, conn, private, string, combo2.text, select, txtlabel.text, tstatus, tchapa, connectdb, combo1.text, tlabel, twork, unload, msgboxresult, txtchapa.text, workload, database, set, dim, cmdupdate_click, frmworkload.show, frmworkload.connworkload


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Updating and saving on database
Updating and saving on database
Updating and saving on database Updating and saving on database
Updating and saving on database
Updating and saving on database
Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database Updating and saving on database
Updating and saving on database
Updating and saving on database
 
Updating and saving on database
Updating and saving on database
 
-->