7 Replies - 299 Views - Last Post: 02 February 2012 - 07:35 PM Rate Topic: *---- 1 Votes

Topic Sponsor:

#1 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

problem i can't update table in database

Posted 02 February 2012 - 10:13 AM

 Public Sub save_edit()
        Dim ssql As String

        ssql = "UPDATE tbl_philhealth SET msr = @txtmsr,sb = @sb,tmc = @tmc,ps = @ps,es = @es WHERE msr=@msr"
        Dim com As New SqlCeCommand
        Using con As SqlCeConnection = New SqlCeConnection("Data Source=" & My.Settings.PATSDB)
            Try
                With com
                    con.Open()
                    com.Parameters.Clear()
                    com.CommandType = CommandType.Text
                    com.CommandText = ssql
                    com.Connection = con
                    com.Parameters.AddWithValue("@msr", txtmsr.Text)
                    com.Parameters.AddWithValue("@sb", txtsb.Text)
                    com.Parameters.AddWithValue("@tmc", txttmc.Text)
                    com.Parameters.AddWithValue("@ps", txtps.Text)
                    com.Parameters.AddWithValue("@es", txtes.Text)
                End With
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error")
            Finally
                con.Close()

                cmdEdit.Text = "Edit"
                cmdClose.Text = "Close"
                disable()
                MsgBox("Successfully Added!", vbInformation, "Success!")
            End Try
        End Using

    End Sub 


No errors at all..
and when i edit some of the textbox it MsgBox("Successfully Added!", vbInformation, "Success!")
BUT no update at all when i RE-run it..

This post has been edited by AdamSpeight2008: 02 February 2012 - 10:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: problem i can't update table in database

#2 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

Re: problem i can't update table in database

Posted 02 February 2012 - 10:18 AM

 Public Sub save_edit()
        Dim ssql As String

        ssql = "UPDATE tbl_philhealth SET msr = @txtmsr,sb = @sb,tmc = @tmc,ps = @ps,es = @es WHERE msr=@msr"
        Dim com As New SqlCeCommand
        Using con As SqlCeConnection = New SqlCeConnection("Data Source=" & My.Settings.PATSDB)
            Try
                With com
                    con.Open()
                    com.Parameters.Clear()
                    com.CommandType = CommandType.Text
                    com.CommandText = ssql
                    com.Connection = con
                    com.Parameters.AddWithValue("@msr", txtmsr.Text)
                    com.Parameters.AddWithValue("@sb", txtsb.Text)
                    com.Parameters.AddWithValue("@tmc", txttmc.Text)
                    com.Parameters.AddWithValue("@ps", txtps.Text)
                    com.Parameters.AddWithValue("@es", txtes.Text)
                End With
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error")
            Finally
                con.Close()

                cmdEdit.Text = "Edit"
                cmdClose.Text = "Close"
                disable()
                MsgBox("Successfully Added!", vbInformation, "Success!")
            End Try
        End Using

    End Sub 


No errors at all..
and when i edit some of the textbox it MsgBox("Successfully Added!", vbInformation, "Success!")
BUT no update at all when i RE-run it..
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 960
  • View blog
  • Posts: 3,353
  • Joined: 25-September 09

Re: problem i can't update table in database

Posted 02 February 2012 - 10:58 AM

You're missing the parameter @txtmsr and you're not doing any execution of the command.

com.ExecuteNonQuery will execute your command that you just defined.

This post has been edited by CharlieMay: 02 February 2012 - 10:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • can't spell BITCH without IT
  • member icon

Reputation: 183
  • View blog
  • Posts: 732
  • Joined: 21-December 11

Re: problem i can't update table in database

Posted 02 February 2012 - 11:03 AM

you haven't executed the SQL query
Was This Post Helpful? 0
  • +
  • -

#5 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

Re: problem i can't update table in database

Posted 02 February 2012 - 05:46 PM

 Public Sub save_edit()
        Dim ssql As String

        ssql = "UPDATE tbl_philhealth SET msr = @txtmsr,sb = @txtsb,tmc = @txttmc,ps = @txtps,es = @txtes WHERE msr=@txtmsr"
        Dim com As New SqlCeCommand
        Using con As SqlCeConnection = New SqlCeConnection("Data Source=" & My.Settings.PATSDB)
            Try
                With com
                    con.Open()
                    com.Parameters.Clear()
                    com.CommandType = CommandType.Text
                    com.ExecuteNonQuery()
                    com.CommandText = ssql
                    com.Connection = con
                    com.Parameters.AddWithValue("@txtmsr", txtmsr.Text)
                    com.Parameters.AddWithValue("@txtsb", txtsb.Text)
                    com.Parameters.AddWithValue("@txttmc", txttmc.Text)
                    com.Parameters.AddWithValue("@txtps", txtps.Text)
                    com.Parameters.AddWithValue("@txtes", txtes.Text)
                End With
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error")
            Finally
                con.Close()

                cmdEdit.Text = "Edit"
                cmdClose.Text = "Close"
                disable()
                MsgBox("Successfully Added!", vbInformation, "Success!")
            End Try
        End Using

    End Sub

End Class 

Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is online

  • Slick.
  • member icon

Reputation: 124
  • View blog
  • Posts: 873
  • Joined: 16-March 11

Re: problem i can't update table in database

Posted 02 February 2012 - 06:20 PM

View Postbry090911, on 02 February 2012 - 06:46 PM, said:

 Public Sub save_edit()
        Dim ssql As String

        ssql = "UPDATE tbl_philhealth SET msr = @txtmsr,sb = @txtsb,tmc = @txttmc,ps = @txtps,es = @txtes WHERE msr=@txtmsr"
        Dim com As New SqlCeCommand
        Using con As SqlCeConnection = New SqlCeConnection("Data Source=" & My.Settings.PATSDB)
            Try
                With com
                    con.Open()
                    com.Parameters.Clear()
                    com.CommandType = CommandType.Text
                    com.ExecuteNonQuery()
                    com.CommandText = ssql
                    com.Connection = con
                    com.Parameters.AddWithValue("@txtmsr", txtmsr.Text)
                    com.Parameters.AddWithValue("@txtsb", txtsb.Text)
                    com.Parameters.AddWithValue("@txttmc", txttmc.Text)
                    com.Parameters.AddWithValue("@txtps", txtps.Text)
                    com.Parameters.AddWithValue("@txtes", txtes.Text)
                End With
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error")
            Finally
                con.Close()

                cmdEdit.Text = "Edit"
                cmdClose.Text = "Close"
                disable()
                MsgBox("Successfully Added!", vbInformation, "Success!")
            End Try
        End Using

    End Sub

End Class 


OK you posted code.. cool... that also tells us nothing.. Does it work? Is there an error? Where's the error occurring? What is the error? What do you want exactly? What is it doing? Some of these questions will help us help you.
Was This Post Helpful? 0
  • +
  • -

#7 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

Re: problem i can't update table in database

Posted 02 February 2012 - 07:01 PM

Finally i get it.. :) com.ExecuteNonQuery() but how to refresh the datagridview after executing it?
Was This Post Helpful? 0
  • +
  • -

#8 trevster344  Icon User is online

  • Slick.
  • member icon

Reputation: 124
  • View blog
  • Posts: 873
  • Joined: 16-March 11

Re: problem i can't update table in database

Posted 02 February 2012 - 07:35 PM

You need to put the data into something like a dataset and then bind it to the datagridview. Ill provide examples when I return to my office.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1