Click here to Skip to main content
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 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2014
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