Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help updating a DB

Posted on 2005-05-01
3
Medium Priority
?
225 Views
Last Modified: 2012-05-05
I would like to know how can I update a record in my db?

I can view the data, delete, but I must be able to update the data in the db, here are my delete function


Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        'get the current position
        Dim current As Integer
        'Get the current position
        current = Me.BindingContext(MyDataset1, "tblContactList").Position

        'Delete the current record
        Me.BindingContext(MyDataset1, "tblContactList").RemoveAt(current)

        Try
            myAdapter.Update(MyDataset1)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        'Re create the structure
        MyDataset1.Clear()
        myAdapter.Fill(MyDataset1)
        get_data(info_data)
        MsgBox("Your data was deleted")

        'Get the new data from the structure
        sCounter = 0

        txtfirst.Text = info_data(sCounter).fName
        txtlast.Text = info_data(sCounter).lName
        txtmail.Text = info_data(sCounter).eMail

    End Sub
0
Comment
Question by:Ennio
  • 2
3 Comments
 
LVL 14

Expert Comment

by:amyhxu
ID: 13906000
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        'get the current position
        Dim current As Integer
        'Get the current position
        current = Me.BindingContext(MyDataset1, "tblContactList").Position

        'Delete the current record
        'Me.BindingContext(MyDataset1, "tblContactList").RemoveAt(current)
        MyDataset1.Tables("tblContactList").Rows(current).Delete()

        Try
            myAdapter.Update(MyDataset1)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        'Re create the structure
        MyDataset1.Clear()
        myAdapter.Fill(MyDataset1)
        get_data(info_data)
        MsgBox("Your data was deleted")

        'Get the new data from the structure
        sCounter = 0

        txtfirst.Text = info_data(sCounter).fName
        txtlast.Text = info_data(sCounter).lName
        txtmail.Text = info_data(sCounter).eMail

    End Sub
0
 
LVL 1

Author Comment

by:Ennio
ID: 13906013
Hi, the code works and delete the record....

I would like  a code where I can update the record I'm looking at.
0
 
LVL 14

Accepted Solution

by:
amyhxu earned 2000 total points
ID: 13906671
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        'get the current position
        Dim current As Integer
        'Get the current position
        current = Me.BindingContext(MyDataset1, "tblContactList").Position

        'Update the current record
        Dim dRow As DataRow = MyDataset1.Tables("tblContactList").Rows(current)
        dRow("fName") = txtfirst.Text
        dRow("lName") = txtlast.Text
        dRow("eMail") = txtmail.Text

        Try
            myAdapter.Update(MyDataset1)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question