Click here to Skip to main content
15,887,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
USE [csoft]
GO
/****** Object:  StoredProcedure [dbo].[Search]    Script Date: 08/08/2010 23:13:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Search] @prd varchar(2), 
						@rep varchar(2), 
						@yy varchar(4),
						@mm varchar(2)
AS

DECLARE @VTEXT VARCHAR(8000)
DECLARE @SNO VARCHAR(4)
Declare @SQL VarChar(8000)
DECLARE @Q VARCHAR(2)
declare @num varchar(10)

DECLARE db_cursor CURSOR FOR 
SELECT sno, view_text 
FROM month_scripts2 
where prd_code = @prd
and   rep_code = @rep

set @num=0
SET @Q = ''''

OPEN db_cursor  
FETCH NEXT FROM db_cursor INTO @SNO,@VTEXT 

WHILE @@FETCH_STATUS = 0  
BEGIN  
	   SET @SQL = @VTEXT 
	   SET @SQL = REPLACE(@SQL,'''MM''',@Q+@MM+@Q)
	   SET @SQL = REPLACE(@SQL,'''YYYY''',@Q+@YY+@Q)	
	   PRINT @sno + ' - ' + @SQL   -- print 
	   Exec ( @SQL)  

       FETCH NEXT FROM db_cursor INTO @SNO,@VTEXT

END   

CLOSE DB_CURSOR
DEALLOCATE DB_CURSOR


Code for Showing Data in Data Grid as follows

C#
SqlConnection conn = new SqlConnection(@"Data Source=SHARIQUE\SQLEXPRESS;Initial Catalog=csoft;Integrated Security=True");

          SqlCommand cmd = new SqlCommand();
          cmd.Connection = conn;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "Search";

          cmd.Parameters.Add("@prd", SqlDbType.VarChar, 50).Value = "11";
          cmd.Parameters.Add("@rep", SqlDbType.VarChar, 50).Value = "31";
          cmd.Parameters.Add("@yy", SqlDbType.VarChar, 50).Value = "2008";
          cmd.Parameters.Add("@mm", SqlDbType.VarChar, 50).Value = "04";


          SqlDataAdapter da = new SqlDataAdapter(cmd);
          conn.Open();
          DataSet ds = new DataSet();
          da.Fill(ds);

          foreach (DataRow dr in ds.Tables[0].Rows)
          {
              foreach (DataColumn dc in ds.Tables[0].Columns)
              {
                  dataGridView1.DataSource = ds.Tables[0].DefaultView;
                  conn.Close();
              }
          }
      }
Posted
Updated 16-Aug-10 19:08pm
v2
Comments
LittleYellowBird 17-Aug-10 3:27am    
Hi, you really need to provide more information. In what way is it 'unanble'? What is the error? What part do think is not working? What have you tried? You will get much better help in that way. :)
shariq1 17-Aug-10 3:32am    
Well Alison, In my Month_scripts2 table (FROM month_scripts2), I have various trends with different name. I make the procedure with the name of Search and when I execute the procedure It shows me all the records which I want. I just simply want to shown all that records in my datagrid but It just show me the record of a single trend, not the all trends with different names.
I ain't getting exactly what the problem, may be some mistake in my procedure or may be some thing wrong in my C# code.
As far as error, it is successfully running.

Thanks-
Sharique

1 solution

Well Alison, In my Month_scripts2 table (FROM month_scripts2), I have various trends with different name. I make the procedure with the name of Search and when I execute the procedure It shows me all the records which I want. I just simply want to shown all that records in my datagrid but It just show me the record of a single trend, not the all trends with different names.
I ain't getting exactly what the problem, may be some mistake in my procedure or may be some thing wrong in my C# code.
As far as error, it is successfully running.

Thanks-
Sharique
 
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