如何编写代码来连接crystal report c#windows窗体 [英] How to write code to connect crystal report c# windows forms

查看:58
本文介绍了如何编写代码来连接crystal report c#windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用于将水晶报告连接到c#windows窗体的代码。我尝试了很多编码,但它在我的电脑上运行,如果我尝试在另一台电脑上运行它会显示错误消息无法打开连接。我是学生,需要解决这个问题才能提交我的项目。任何人都可以帮我解决这个问题。







这是我的编码部分:



private void Preview_Click(object sender,EventArgs e)

{

SqlConnection cnn;

string connectionString = null;

string sql = null;



connectionString = @Data Source = .\SQLEXPRESS; Initial Catalog = trydb_1; Integrated Security = True;

cnn = new SqlConnection(connectionString);

cnn.Open();

sql =SELECT ID,pay_id,日期,custname,描述,chqno,duedate,accname,金额来自付款;

SqlDataAdapter dscmd = new SqlDataAdapter(sql,cnn);

ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(@D:\Completing\WindowsFormsApplication1 \ payments11.rpt);

crystalReportViewer1.ReportSource = cr yRpt;

crystalReportViewer1.Refresh();

}

I need code for connect a crystal report to c# windows forms. I've tried many coding but its working on my pc, if i try to run in another pc it shows an error message "Failed to open the connection". I am a student and need to solve this issue to submit my project. Can anyone help me to solve this issue.



this is my coding part :

private void Preview_Click(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString = null;
string sql = null;

connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=trydb_1;Integrated Security=True";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "SELECT ID,pay_id,date,custname,description,chqno,duedate,accname,amount FROM payments";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"D:\Completing\WindowsFormsApplication1\payments11.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}

推荐答案

我假设数据库托管于您的PC,因为您使用localhost服务器名称。如果我错了,请纠正我:



I assume that the DB is hosted on your PC, because you use the localhost server name. Correct me if I'm wrong:

=.\SQLEXPRESS;Initial





为了在另一台PC上工作,你必须更换。使用您的计算机名称或IP地址,当然其他PC需要能够看到您的PC。



In order to make this work on another PC, you have to replace the "." with your computer name or IP address, and off course the other PC needs to be able to "see" your PC.


这篇关于如何编写代码来连接crystal report c#windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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