Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将数据从SQL Server数据库加载到Crystal Reports c#_C#_Sql Server_Crystal Reports - Fatal编程技术网

无法将数据从SQL Server数据库加载到Crystal Reports c#

无法将数据从SQL Server数据库加载到Crystal Reports c#,c#,sql-server,crystal-reports,C#,Sql Server,Crystal Reports,我正在使用SQL Server数据库处理C#中的Crystal Reports,我无法继续我的项目,因为我遇到了一个错误 加载保存报告异常 在我要设置Crystal报表数据源的行上 任何帮助都将不胜感激 这是我的密码: SqlConnection con = new SqlConnection(); string conString = @"data source =JR-PC\SQLEXPRESS;initial catalog = election;integrated security =

我正在使用SQL Server数据库处理C#中的Crystal Reports,我无法继续我的项目,因为我遇到了一个错误

加载保存报告异常

在我要设置Crystal报表数据源的行上

任何帮助都将不胜感激

这是我的密码:

SqlConnection con = new SqlConnection();
string conString = @"data source =JR-PC\SQLEXPRESS;initial catalog = election;integrated security =true;";
string sql = "Select can_names,can_pos,partylist,num_votes from tbl_Candidates";

con = new SqlConnection(conString);
con.Open();

SqlDataAdapter da = new SqlDataAdapter(sql, con);
ReportPracice._DATASETS.DataSet1 ds = new ReportPracice._DATASETS.DataSet1();
da.Fill(ds, "tbl_Candidates");

MessageBox.Show(ds.Tables[1].Rows.Count.ToString()); //Returns a value of "40";
con.Close();

ReportPracice._REPORTS.CrystalReport1 rpt = new ReportPracice._REPORTS.CrystalReport1();
rpt.SetDataSource(ds.Tables[1]); //in this line, where I am getting that error.
crystalReportViewer1.ReportSource = rpt;
crystalReportViewer1.Refresh();
尝试使用“0”而不是“1”

C#索引是基于零的,而不是基于1的

ds.表格[0]

ds.表格[“待定候选人”]

或者检查一下名字

string tName = ds.Tables[1].TableName;
我知道你在按“1”排

当有疑问时,做一个测试

string temp = ds.GetXml(); 
然后得到temp的值并查看它。 这总是能说明问题

如果您有一个强类型数据集,那么就不应该使用基数引用。(“0”或“1”等)。使用表的名称

然后检查报告以查看引用的数据集(表)。你可能必须用记事本打开报告,四处搜寻

您处理数据集的表名的方式是“loosey-goosey”,并且可能在某些地方名称不匹配