4

I want to create a report viewer in ASP.NET that presents to the users their data. the data for all the users is located in the same table.

for now I created DBDataSet and in the TableAdapter there is this method

GetData(@idNumber, @userNumber)

in code behind of the screen that I want to show the report viewer I wrote:

FlightsDBDataSetTableAdapters.ReservationsTableAdapter ReservationsTableAdapter;
ReservationsTableAdapter = new FlightsDBDataSetTableAdapters.ReservationsTableAdapter();
FlightsDBDataSet.ReservationsDataTable newReservationTable;
newReservationTable = ReservationsTableAdapter.GetData(userId, userName);
ObjectDataSource1.SelectParameters.Add("userName", userName);
ObjectDataSource1.SelectParameters.Add("idNumber", userId);

when I run this I get the next error

An error has occurred during report processing. ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetData(idNumber, userName)' that has parameters: userName, idNumber.

SO, my question is where do I need to write the method GetData and how can I generate the report with the right data.

thanks a lot.

Ofir A.
  • 3,112
  • 11
  • 57
  • 83

1 Answers1

0

Try this out.

1.Create a method which will return db null if parameter is not passed in the stored procedure

public static object GetDataValue(object o)
{
    if (o == null || String.Empty.Equals(o))
        return DBNull.Value;
    else
        return o;
}

2.Create a method which will called the stored procedure and fill the dataset.

public DataSet GetspTest(string userName, string userId) {

try
{
    DataSet oDS = new DataSet();
    SqlParameter[] oParam = new SqlParameter[2];


    oParam[0] = new SqlParameter("@userName", GetDataValue(userName));
    oParam[1] = new SqlParameter("@idNumber", GetDataValue(userId));

    oDS = SqlHelper.ExecuteDataset(DataConnectionString, CommandType.StoredProcedure, "spTest", oParam);
    return oDS;
}
catch (Exception e)
{
    ErrorMessage = e.Message;
    return null;
}

}

  1. Now you add the dataset let us say 'DataSet1.xsd' Drag and Drop the TableAdapter and it will ask you the following details

    3.1 Connection String (Either Select the existing connection string or create new connection string)

    3.2 Choose Command Type (Now select the existing stored Procedure, specify the stored procedure with you have create earlier to display details in the report

    3.3 Choose Methods to Generate (check both Fill a Datatable and Return a datatable

    3.4 Click on Next and Submit ( Now your dataset is really to use in the report)

    1. Create a report and use this DataSet1 as datasource.