Click here to Skip to main content
11,410,118 members (61,795 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ListBox , +
i have a listbox contains some brand names of products. i make them a string with a for loop like :

string kod;
string grupkodu;
for (int i = 0; i < listBox2.Items.Count; i++)
                {
                    grupkodu = grupkodu + kod + "'%" + listBox1.Items[i].ToString() + "%'";
                    kod = "or GRUP_KODU LIKE ";
                }


and my stored procedure is :

ALTER PROC [dbo].[AHMETILKKARTHAREKETGETIR]
(
@CARIKOD VARCHAR(10),
@BASTARIH DATETIME,
@BITTARIH DATETIME,
@GRUPKOD VARCHAR(999)
)
AS
BEGIN
SELECT STHAR_TARIH AS 'TARIH',FISNO AS 'FATURA NO',TBLSTSABIT.STOK_KODU AS 'STOK KODU',TBLSTSABIT.URETICI_KODU AS 'URETICI KODU',STHAR_GCMIK AS 'ADET'
    FROM TBLSTSABIT LEFT OUTER JOIN TBLSTHAR ON TBLSTSABIT.STOK_KODU = TBLSTHAR.STOK_KODU
        WHERE STHAR_ACIKLAMA =@CARIKOD AND STHAR_TARIH>=@BASTARIH AND STHAR_TARIH<=@BITTARIH AND
            (GRUP_KODU LIKE @GRUPKOD )
ORDER BY STHAR_TARIH,FISNO,URETICI_KODU
END
for example, my listbox contains 3 items named 'CTR,DEPO,AISIN'. i make them a string with my loop, my variable grupkodu is equal to :
'%CTR%' or GRUP_KODU like '%DEPO%' or GRUP_KODU like '%AISIN%'
.
i try to pass the @GRUPKOD variable of my stored procedure this string and try to select multiple rows from my database. but i got an error while doing this. i dont know why.

how can i send multiple variables with or statement to sql stored procedure? what is the right way to do this?
Posted 24-Apr-13 0:05am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Friend,

Check the following link....

If u are using SQL server 2008 or advance then u can use User Define Type for this...
Sending a DataTable to a Stored Procedure[^]
Regards,
GVPrabu
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 169
1 OriginalGriff 70
2 BillWoodruff 70
3 Maciej Los 68
4 Philippe Mori 60
0 Sergey Alexandrovich Kryukov 8,755
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web02 | 2.8.150414.5 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100