Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass one fragment of query to store procedure my query in SP is
SQL
if @Mode= 'Searching'
BEGIN
Select [Hadith_Text]
      ,[Hadith_Urdu]
      ,[Hadith_English]
      ,[Chapter_English_Name]
      ,[Chapter_Urdu_Name]
      ,[Baab_English_Name]
      ,[Baab_Urdu_Name]
      ,[Baab_Id]
      ,[Hadith_Book_Number]
	  From Hadiths_old
	  Where Baab_Id < 100
	  AND = @WhereClause
	  order by ID
END

@WhereClause i am passing as parameter from C#
and this is
C#
if (clbBooksName.GetItemChecked(0) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 1 ";
            }
             if (clbBooksName.GetItemChecked(1) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 2 ";
            }
           if (clbBooksName.GetItemChecked(2) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 3 ";
            }
            if (clbBooksName.GetItemChecked(3) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 4 ";
            }
            if (clbBooksName.GetItemChecked(4) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 5 ";
            }
             if (clbBooksName.GetItemChecked(5) == true)
            {
                BookSelection += "OR Hadith_Book_Number = 6 ";
            }
            foreach (DataGridViewRow Datarow in dataGridView1.Rows)
            {
                if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null && Datarow.Cells[3].Value != null)
                {
                    WhereClause += 
Datarow.Cells[0].Value.ToString() + " " + Datarow.Cells[1].Value.ToString() + " " + Datarow.Cells[2].Value.ToString() + " " + Datarow.Cells[3].Value.ToString();
                }
            }

Posted

1 solution

You want to do something like this:
if @Mode= 'Searching'
BEGIN
Select [Hadith_Text]
      ,[Hadith_Urdu]
      ,[Hadith_English]
      ,[Chapter_English_Name]
      ,[Chapter_Urdu_Name]
      ,[Baab_English_Name]
      ,[Baab_Urdu_Name]
      ,[Baab_Id]
      ,[Hadith_Book_Number]
	  From Hadiths_old
	  Where Baab_Id < 100 + ' ' + @WhereClause
	  order by ID
END


This will work, provided your "@WhereClause" variable is assigned the value of "BookSelection" in your C# code.
 
Share this answer
 
Comments
Muhamad Faizan Khan 29-Oct-13 11:59am    
@WhereClause contain not only book Selection there is more thank my 5
Richard C Bishop 29-Oct-13 12:00pm    
You are welcome. Come back anytime.

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