Welcome to Dream.In.Code
Become a VB Expert!

Join 149,486 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,344 people online right now. Registration is fast and FREE... Join Now!




problem in update ms access data table

 
Reply to this topicStart new topic

problem in update ms access data table

nb718
7 May, 2007 - 09:03 PM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 4


My Contributions
what's going wrong that codes not work fine : no error message and no update to my data table when I query record again.

CODE

    Private Sub updateRecord()
        Try
            If (txtHN.Text <> Nothing) Then
                Dim conn1 As OleDbConnection = New OleDbConnection
                conn1.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\db.mdb"
                conn1.Open()

                Dim cmdQ As New OleDbCommand
                cmdQ.Connection = conn1
                cmdQ.CommandText = "SELECT * FROM Treatment WHERE Treatment.HospNo ='" & txtHN.Text & "'" ' AND Treatment.TreatDate ='" & lblx.Text & "'"
                Dim daQ As OleDbDataAdapter = New OleDbDataAdapter(cmdQ)
                Dim dsQ As DataSet = New DataSet
                Dim dtQ As DataTable = New DataTable

                daQ.Fill(dsQ)
                daQ.FillSchema(dsQ, SchemaType.Source)
                dtQ = dsQ.Tables(0)

                Dim drw As DataRow
                Dim key As String = lblx.Text.ToString
                drw = dtQ.Rows.Find(key)

                MessageBox.Show(drw("Summary"))

                drw.BeginEdit()
                drw("Summary") = tbxSmy.Text
                drw.EndEdit()
                stb.Text = " file 檔案: " & txtHN.Text & "; date 日期: " & lblx.Text & " is updated 經巳存檔。"

                Dim cmdBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(daQ)
                daQ.Update(dsQ)
                daQ.UpdateCommand.CommandText = "UPDATE Treatement SET Treatment.Summary ='" & tbxSmy.Text & "' WHERE TreatDate='" & lblx.Text & "' AND Treatment.HospNo ='" & txtHN.Text & "'"

                daQ.UpdateCommand.ExecuteNonQuery()
                conn1.Close()

                clrAll()

            Else
                stb.Text = " invalid operation 此操作無效。"


            End If
        Catch ex As Exception

        End Try

    End Sub

User is offlineProfile CardPM
+Quote Post

tody4me
RE: Problem In Update Ms Access Data Table
8 May, 2007 - 05:16 AM
Post #2

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,349



Thanked: 5 times
Dream Kudos: 100
My Contributions
take the and out of the update statement, and replace it with a comma.
QUOTE

CODE

daQ.UpdateCommand.CommandText = "UPDATE Treatement SET Treatment.Summary ='" & tbxSmy.Text & "' WHERE TreatDate='" & lblx.Text & "' AND Treatment.HospNo ='" & txtHN.Text & "'"



to this:
CODE

daQ.UpdateCommand.CommandText = "UPDATE Treatement SET Treatment.Summary ='" & tbxSmy.Text & "' WHERE TreatDate='" & lblx.Text & "', Treatment.HospNo ='" & txtHN.Text & "'"


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:54PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month