Click here to Skip to main content
15,914,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to update any row that is been checked in a listview control. Here is my code:


VB
Dim constr As String = "Data Source=adesina-pc;Initial Catalog=Northwind;Integrated Security=True"

       Using con As SqlConnection = New SqlConnection(constr)
           Using cmd As SqlCommand = New SqlCommand()
               With cmd
                   .CommandText = "UpdateCat"
                   .CommandType = CommandType.StoredProcedure
                   .Connection = con
               End With

               Try
                   con.Open()
                   Dim checkeditems As ListView.CheckedListViewItemCollection = ListView1.CheckedItems
                   Dim item As ListViewItem = New ListViewItem()
                   For Each item In checkeditems
                       cmd.ExecuteNonQuery()
                   Next
               Catch ex As Exception
                   Throw
               End Try
           End Using
       End Using



Here is my stored procedure:

SQL
ALTER PROCEDURE dbo.UpdateCat
    
    @CatID int
    
AS
    UPDATE Categories SET NUpdate = 'Updates'


My problem is instead of updating the checked ones it is updating all list items in the listview.

Please am i doing wrong

Thanks in advance
Posted
Updated 18-Jun-10 1:33am
v2
Comments
Ankur\m/ 18-Jun-10 7:36am    
You could have updated your previous post instead of creating a new one for the same question.

1 solution

In your Stored Proc you have a parameter @CatID, a value for which, I assume, should be passed to it from your code. No value is being passed.

Then once your stored proc is run the parameter is not used anyway.

Computers are not mind readers, you have to tell them exactly what to do.

To start you off I would suggest that you add a WHERE clause to your stored proc to utilise the @CatID passed in.

Then do some research on parameterized queries, possibly start here[^].

Good luck! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900