Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a listbox contains some brand names of products. i make them a string with a for loop like :

C#
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 :

SQL
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 :
C#
'%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

1 solution

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
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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