I want to display data from DataSet
to my ReportViewer
. Currently I have 4 reports which contain basic data like NameSurname
, NetworkLogin
, Status
, OrgUnitID
and I created a filter which will filter this data using Status
and OrgUnitID
.
So far here is code
public void BindToData()
{
try
{
DataSet ds = new DataSet();
string connString = @"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=DesignSaoOsig1;Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
string strproc = "TestReport";
using (SqlDataAdapter sda = new SqlDataAdapter(strproc, connString))
{
SqlCommand cmd = new SqlCommand();
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("@Status", SqlDbType.Bit).Value = ddlStatus.SelectedValue == "1" ? true : false;
sda.SelectCommand.Parameters.Add("@OrgJed", SqlDbType.Int).Value = ddlOrgUnit.SelectedValue;
sda.Fill(ds);
XtraReport report = new XtraReport();
string nazivIzvjestaja = ds.Tables[0].Rows[0].ItemArray[0].ToString();
if (string.IsNullOrEmpty(nazivIzvjestaja))
{
conn.Close();
}
report.DataSource = ds;
report.DataMember = ds.Tables[0].ToString();
string[] arrvalues = new string[ds.Tables[0].Rows.Count];
for (int loopcounter = 0; loopcounter < ds.Tables[0].Rows.Count; loopcounter++)
{
//assign dataset values to array
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["PrezimeIme"].ToString();
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["NetworkLogin"].ToString();
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["Status"].ToString();
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["OrgUnitID"].ToString();
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["DT_Creat"].ToString();
arrvalues[loopcounter] = ds.Tables[0].Rows[loopcounter]["DT_Modif"].ToString();
}
}
}
catch (Exception)
{
throw;
}
}
So far I use DevExpress
. SO far I catch all data using for loop
but I have problem and I don't know how to display these data to Report
.
Any help will be more then welcome.
As you have already said that you have bound the DataSet with the report you can preview the report for checking the result by inserting the following line after loop finished:
report.ShowPreview();
I noticed that you are using an untyped dataset for DevExpress it is need to be serialized as it is explained in detail official post of Dev Express: Check for the Official Website blog