Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a windows form frmPurchase which contains a lisview (purchaseListView).
i also have a class purchase.cs which contains function that calls stored procedure.
i want to get the items of listview as parameters of stored procedure in class purchase.cs
how can i do it?

regards
bunzitop
Posted
Comments
Anurag Sinha V 7-Mar-13 8:52am    
hey,

does ur stored procedure support parameters? I mean to say that when you are calling your SP in the purchase.cs class, does it compile properly coz i guess you are not providing any parameters over there??
Am i successful in interpreting your situation?

-anurag
bunzitop 7-Mar-13 10:21am    
when i passed parameters (values other than from listview) to sp in purchase it worked properly

u have to do something like this..
1.Make variable of ur purchase class.
2.Use for loop to retrieve item from listview
3.use Item.Text to retrieve value
4.pass that values to method of purchase.cs

for example
C#
purchase objPuchase = new purchase();
string value1;
string value2;
foreach (ListViewItem item in purchaseListView.Items)
{
    value1 =  item.SubItems[0].Text.ToString();
    value2 =  item.SubItems[1].Text.ToString();
//repeat it for all 10 rows
    objPuchase.UrStoreProcedureMethodName(value1 ,value2);
}

hope it will help
 
Share this answer
 
v2
Comments
bunzitop 7-Mar-13 10:26am    
Thank you for your kind help.
your code gets all the items to variable, its good but my requirement is
i need to get all the values of items of listview through a loop and pass it as parameter of SP. suppose i have 10 rows in my listview, and i need to insert all those rows in DB through Sp which is in class purchase, how to manage a loop for this?? this is my confusion.
waiting for reply asap.
regards
bunzitop
Pallavi Waikar 7-Mar-13 22:59pm    
refer following demo ....hope it will help u
another solution is create one new class items using it get and set values by property.
and in purchaseclass create generic variable of list of type item .
pass this values to item class.
In ur store procedure method iterate this values from list and pass to store procedure as parameter ..exampal
1.create item calss
C#
public class Item
    {
        string name;
        string lname


        public Item(string name, string lname)
        {
            this.name = name;
            this.lname = lname;

        }



        public string Name
        {
            get
            {
                return this.name;
            }
        }
        public string MyLname
        {
            get
            {
                return this.lanme;
            }
        }

    }


2.In listview page pass this values to items
purchase  objpurchase =new purchase();
foreach (ListViewItem item in purchaseListView.Items)
{
    value1 =  item.SubItems[0].Text.ToString();
    value2 =  item.SubItems[1].Text.ToString();
//repeat it for all 10 rows
    objPuchase.Items.Add( new Item(value1,value2));
}


3.change ur purchase class create generic variable as public List of type Items class and iterate values from it.
C#
public class purchase
    {
        public List<Item> Items;

        double InvoiceTotal;

        public Invoice()
        {
            Items = new List<Item>();
        }



        public void StoreProcedureMethos()
        {
        string name2;
        string lanme2;
             foreach (Item i in this.Items)
                {
                    name2=i.Name;
                    lanme2=i.MyLname;
            //ur store procedure code pass this as parameter to it

                }


        }

    }


try it as demo ...change as per ur requirements
 
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