dcsimg
Results 1 to 2 of 2

Thread: how to update only selected data in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    1

    how to update only selected data in vb.net

    using the code below i am able to update all rows with status ="not sold"
    what i really want is to update only 3 rows
    Dim s As String
    Dim y As Integer
    y = 3
    conn.Open()
    s = "not sold"
    Dim query1 As String = "update Barrel_tbl set status=@status where status='" & s & "' "
    Dim cmd4 As New SqlCommand(query1, conn)
    cmd4.Parameters.AddWithValue("@status", "sold")
    cmd4.ExecuteNonQuery()
    conn.Close()
    my database has sr_no,Bid,Status
    example
    Sr_no Bid Status
    1 B11 not sold
    2 B12 not sold
    3 B13 not sold
    4 B14 not sold
    5 B15 not sold

    my output should be
    Sr_no Bid Status
    1 B11 sold
    2 B12 sold
    3 B13 sold
    4 B14 not sold
    5 B15 not sold

    plz help i am using sql database

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,802

    Re: how to update only selected data in vb.net

    Your WHERE clause controls what records get updated. If you want three specific records updated then specify a condition in your WHERE clause that matches only those records.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width