显示报表页面C#代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
ReportDocument oRpt = new ReportDocument();
oRpt.Load(Server.MapPath("CrystalReport.rpt"));
database da = new database();
string sql = "select * from test";
DataTable dt = da.getdt(sql);
oRpt.SetDataSource(dt);
CrystalReportViewer1.ReportSource = oRpt;
CrystalReportViewer1.DataBind();
}
12 个解决方案
#1
form驗證的用戶名和密碼?
#2
你的用户名和密码是否设置了SESSION状态··?··
#3
database的c#代码:
namespace DAL
{
public class database
{
public string connectstr = ConfigurationSettings.AppSettings["CNString"].ToString();
public SqlTransaction sqltran;
public SqlConnection thisConnection;
public SqlCommand mcommend;
public database()
{
thisConnection = new SqlConnection(connectstr);
}
public DataSet getds(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet);
Close();
return thisDataSet;
}
public DataTable getdt(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataTable thisDataTable = new DataTable();
thisAdapter.Fill(thisDataTable);
Close();
return thisDataTable;
}
public void Close()
{
if (thisConnection != null)
thisConnection.Close();
}
public void Dispose()
{
if (thisConnection != null)
{
thisConnection.Dispose();
thisConnection = null;
}
}
~database()
{
try
{
if(thisConnection!=null)
thisConnection.Close();
}
catch{}
try
{
Dispose();
}
catch{}
}
}
}
namespace DAL
{
public class database
{
public string connectstr = ConfigurationSettings.AppSettings["CNString"].ToString();
public SqlTransaction sqltran;
public SqlConnection thisConnection;
public SqlCommand mcommend;
public database()
{
thisConnection = new SqlConnection(connectstr);
}
public DataSet getds(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet);
Close();
return thisDataSet;
}
public DataTable getdt(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataTable thisDataTable = new DataTable();
thisAdapter.Fill(thisDataTable);
Close();
return thisDataTable;
}
public void Close()
{
if (thisConnection != null)
thisConnection.Close();
}
public void Dispose()
{
if (thisConnection != null)
{
thisConnection.Dispose();
thisConnection = null;
}
}
~database()
{
try
{
if(thisConnection!=null)
thisConnection.Close();
}
catch{}
try
{
Dispose();
}
catch{}
}
}
}
#4
你的用户名和密码是否设置了SESSION状态··?··
---------------------
不好意思,我很新,这个是什么意思啊?
---------------------
不好意思,我很新,这个是什么意思啊?
#5
点击第二页的时候就这样一个页面:
The report you requested requires further information.
--------------------------------------------------------------------------------
DataSet1
Server name:
Database name:
User name:
Password:
Use Integrated Security
The report you requested requires further information.
--------------------------------------------------------------------------------
DataSet1
Server name:
Database name:
User name:
Password:
Use Integrated Security
#6
在给:ReportDocument 设置数据源的时候必须要ArraList对象
否则 即使你输入了密码也没用
否则 即使你输入了密码也没用
//这个方法写在page_Load前面 并且方法名不要改变
protected void page_Init(object sender, EventArgs e)
{
DataSet ds = Cum.GetData();//这里我是获取的一个DataSet对象
ArrayList al = new ArrayList();
for (int i = 0; i < ds.Tables["cum"].Rows.Count; i++)
{
Cum cum = new Cum();//Cum是一个类,我在里面定义了属性,因为我在选择数据专家的时候选择的是.NET对象
cum.CustomerID = ds.Tables["cum"].Rows[i]["CustomerID"].ToString();
cum.CompanyName = ds.Tables["cum"].Rows[i]["CompanyName"].ToString();
cum.Address = ds.Tables["cum"].Rows[i]["Address"].ToString();
al.Add(cum);
}
string path = Server.MapPath("CrystalReport.rpt");
ReportDocument rd = new ReportDocument();
rd.Load(path);
rd.SetDataSource(al);
this.CrystalReportViewer1.ReportSource = rd;
}
public class Cum
{
public Cum()
{
}
private string _CustomerID;
public string CustomerID
{
get { return _CustomerID; }
set { _CustomerID = value; }
}
private string _CompanyName;
public string CompanyName
{
get { return _CompanyName; }
set { _CompanyName = value; }
}
private string _Address;
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public static DataSet GetData()
{
SqlConnection conn = new SqlConnection("server=.;database=northwind;uid=sa;pwd=;");
SqlDataAdapter sda = new SqlDataAdapter("select CustomerID,CompanyName,Address from Customers",conn);
DataSet ds = new DataSet();
sda.Fill(ds,"cum");
return ds;
}
}
#7
是 ArrayList 对象
#8
MyAdapter.Fill(ds, "DataTable1"); 这里的DataTable1必须与创建的Dataset1中的表名相同,否则会出现
信息。写成MyAdapter.Fill(ds);也不行。
参考
信息。写成MyAdapter.Fill(ds);也不行。
参考
#9
楼上的有道理
#10
MyAdapter.Fill(ds, "DataTable1"); 这里的DataTable1必须与创建的Dataset1中的表名相同,否则会出现
信息。写成MyAdapter.Fill(ds);也不行。
----------------------------------------------
是在database.cs里面改?
信息。写成MyAdapter.Fill(ds);也不行。
----------------------------------------------
是在database.cs里面改?
#11
而且我发现打印和存盘也不行都,都是那样要输入用户名密码。
#12
jijunwu
----------------------------------------
你是对的, 我用你的方法可以了。
----------------------------------------
你是对的, 我用你的方法可以了。
#1
form驗證的用戶名和密碼?
#2
你的用户名和密码是否设置了SESSION状态··?··
#3
database的c#代码:
namespace DAL
{
public class database
{
public string connectstr = ConfigurationSettings.AppSettings["CNString"].ToString();
public SqlTransaction sqltran;
public SqlConnection thisConnection;
public SqlCommand mcommend;
public database()
{
thisConnection = new SqlConnection(connectstr);
}
public DataSet getds(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet);
Close();
return thisDataSet;
}
public DataTable getdt(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataTable thisDataTable = new DataTable();
thisAdapter.Fill(thisDataTable);
Close();
return thisDataTable;
}
public void Close()
{
if (thisConnection != null)
thisConnection.Close();
}
public void Dispose()
{
if (thisConnection != null)
{
thisConnection.Dispose();
thisConnection = null;
}
}
~database()
{
try
{
if(thisConnection!=null)
thisConnection.Close();
}
catch{}
try
{
Dispose();
}
catch{}
}
}
}
namespace DAL
{
public class database
{
public string connectstr = ConfigurationSettings.AppSettings["CNString"].ToString();
public SqlTransaction sqltran;
public SqlConnection thisConnection;
public SqlCommand mcommend;
public database()
{
thisConnection = new SqlConnection(connectstr);
}
public DataSet getds(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet);
Close();
return thisDataSet;
}
public DataTable getdt(string sql)
{
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, connectstr);
DataTable thisDataTable = new DataTable();
thisAdapter.Fill(thisDataTable);
Close();
return thisDataTable;
}
public void Close()
{
if (thisConnection != null)
thisConnection.Close();
}
public void Dispose()
{
if (thisConnection != null)
{
thisConnection.Dispose();
thisConnection = null;
}
}
~database()
{
try
{
if(thisConnection!=null)
thisConnection.Close();
}
catch{}
try
{
Dispose();
}
catch{}
}
}
}
#4
你的用户名和密码是否设置了SESSION状态··?··
---------------------
不好意思,我很新,这个是什么意思啊?
---------------------
不好意思,我很新,这个是什么意思啊?
#5
点击第二页的时候就这样一个页面:
The report you requested requires further information.
--------------------------------------------------------------------------------
DataSet1
Server name:
Database name:
User name:
Password:
Use Integrated Security
The report you requested requires further information.
--------------------------------------------------------------------------------
DataSet1
Server name:
Database name:
User name:
Password:
Use Integrated Security
#6
在给:ReportDocument 设置数据源的时候必须要ArraList对象
否则 即使你输入了密码也没用
否则 即使你输入了密码也没用
//这个方法写在page_Load前面 并且方法名不要改变
protected void page_Init(object sender, EventArgs e)
{
DataSet ds = Cum.GetData();//这里我是获取的一个DataSet对象
ArrayList al = new ArrayList();
for (int i = 0; i < ds.Tables["cum"].Rows.Count; i++)
{
Cum cum = new Cum();//Cum是一个类,我在里面定义了属性,因为我在选择数据专家的时候选择的是.NET对象
cum.CustomerID = ds.Tables["cum"].Rows[i]["CustomerID"].ToString();
cum.CompanyName = ds.Tables["cum"].Rows[i]["CompanyName"].ToString();
cum.Address = ds.Tables["cum"].Rows[i]["Address"].ToString();
al.Add(cum);
}
string path = Server.MapPath("CrystalReport.rpt");
ReportDocument rd = new ReportDocument();
rd.Load(path);
rd.SetDataSource(al);
this.CrystalReportViewer1.ReportSource = rd;
}
public class Cum
{
public Cum()
{
}
private string _CustomerID;
public string CustomerID
{
get { return _CustomerID; }
set { _CustomerID = value; }
}
private string _CompanyName;
public string CompanyName
{
get { return _CompanyName; }
set { _CompanyName = value; }
}
private string _Address;
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public static DataSet GetData()
{
SqlConnection conn = new SqlConnection("server=.;database=northwind;uid=sa;pwd=;");
SqlDataAdapter sda = new SqlDataAdapter("select CustomerID,CompanyName,Address from Customers",conn);
DataSet ds = new DataSet();
sda.Fill(ds,"cum");
return ds;
}
}
#7
是 ArrayList 对象
#8
MyAdapter.Fill(ds, "DataTable1"); 这里的DataTable1必须与创建的Dataset1中的表名相同,否则会出现
信息。写成MyAdapter.Fill(ds);也不行。
参考
信息。写成MyAdapter.Fill(ds);也不行。
参考
#9
楼上的有道理
#10
MyAdapter.Fill(ds, "DataTable1"); 这里的DataTable1必须与创建的Dataset1中的表名相同,否则会出现
信息。写成MyAdapter.Fill(ds);也不行。
----------------------------------------------
是在database.cs里面改?
信息。写成MyAdapter.Fill(ds);也不行。
----------------------------------------------
是在database.cs里面改?
#11
而且我发现打印和存盘也不行都,都是那样要输入用户名密码。
#12
jijunwu
----------------------------------------
你是对的, 我用你的方法可以了。
----------------------------------------
你是对的, 我用你的方法可以了。