如何使用商店程序打印数据集 [英] how can use store procedure to print with dataset

查看:81
本文介绍了如何使用商店程序打印数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在水晶报告中使用用户名和密码,并且从dataGridView到商店程序的
i传递值





商店程序是:

i need to use username and password in crystal report and
i pass value from dataGridView to the store procedure


the store procedure is:

Create proc [dbo].[PrintCatCustomersTbl]
@catId int
as
select catId,catName,catNote from CatCustomersTbl where catId=@catId











这是我从dataGridView打印的代码:








and this is my code to print from dataGridView:

Report.ReportCatProductsSingle reportcustomer = new Report.ReportCatProductsSingle();
 reportcustomer.SetParameterValue("@catId",this.dataGridView1.CurrentRow.Cells[0]
.Value.ToString());
            Report.FormCatProducts fmct = new Report.FormCatProducts();
          
            fmct.crystalReportViewer1.ReportSource = reportcustomer;
            fmct.ShowDialog();









可以我使用数据集来使用UserName和密码并从dataGridView打印

赞:这是:






Can i use the dataset to use the UserName and Password and Print from dataGridView
Like This:

string DatabaseServer = ConfigurationManager.AppSettings["Server"];
            string userId = ConfigurationManager.AppSettings["Userid"];
            string Password = ConfigurationManager.AppSettings["Password"];
            string DataBaseName = ConfigurationManager.AppSettings["DataBase"];

推荐答案

您可以尝试这种方式:



DataTable dt = new DataTable();





for(int i = 0; i< yourgridviewname.rows.count ; i ++)

{

//从网格视图中获取存储过程的参数

string catId = YourGridViewName.Items [i] .Text;



SqlCommand cmd = new SqlCommand(PrintCatCustomersTbl,conn);

cmd.Parameters.Add(@ catId ,SqlDbType.int).Value = catId;

cmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter adp = new SqlDataAdapter(cmd);

adp.Fill(dt);

/////您也可以在这里逐行获取数据/////

}

//显示从存储过程返回的数据列表

AnyControlName.DataSource = dt;

AnyControlName.DataBind();
You can try this way:

DataTable dt = new DataTable();


for (int i=0;i<yourgridviewname.rows.count;i++)
{
//To get the Paramater of the stored procedure from Grid view
string catId = YourGridViewName.Items[i].Text;

SqlCommand cmd = new SqlCommand("PrintCatCustomersTbl", conn);
cmd.Parameters.Add("@catId", SqlDbType.int).Value =catId;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
///// you can also here get your the data row by row/////
}
// to display the list of data returned from the stored procedure
AnyControlName.DataSource = dt;
AnyControlName.DataBind();


这篇关于如何使用商店程序打印数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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