无法通过此存储过程显示datagrid中的所有记录 [英] Unable to show all records in datagrid through this Stored Procedure

查看:81
本文介绍了无法通过此存储过程显示datagrid中的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();
              }
          }
      }

推荐答案

好艾莉森,在我的Month_scripts2表(FROM month_scripts2)中,我有各种各样使用不同名称的趋势.我使用搜索"的名称创建该过程,并在执行该过程时显示了我想要的所有记录.我只想显示我的数据网格中的所有记录,但它只显示一个趋势的记录,而不是所有具有不同名称的趋势的记录.
我没有得到确切的问题,可能是我的过程中出现了一些错误,也可能是我的C#代码中出现了一些错误.
就错误而言,它已成功运行.

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


这篇关于无法通过此存储过程显示datagrid中的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆