0

I am trying to assign a PagedDataSource to ExecuteReader() but I get the error saying it needs to be ICollection.

I want all the data it returns as it is going to be assigned in a repeater. At first i just assigned the repeater to the cmd.ExecuteReader() and it worked ok, now they want paging and I'm not sure how to alter the query to produce an Array.

conn.Open();

var cmd = new SqlCommand("[safetyGuidanceSearch]", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@iwc", inwardCode);
cmd.Parameters.AddWithValue("@owc", outwardCode);

var objPds = new PagedDataSource();
objPds.DataSource = cmd.ExecuteReader();// turn into an array

What should I be trying to do?

2 Answers 2

1

You need to fill the array first.

var result = new List<whatevertypespreturns>();
var reader = cmd.ExecuteReader();
while(reader.Read()){
    result.add(reader.GetXxxx(0);
}
objPds.DataSource = result.ToArray();
Sign up to request clarification or add additional context in comments.

Comments

0

You can do something like this

    SqlDataReader dr;
    DataTable dt = new DataTable();
    conn.Open();

    var cmd = new SqlCommand("[safetyGuidanceSearch]", conn);
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.AddWithValue("@iwc", inwardCode);
    cmd.Parameters.AddWithValue("@owc", outwardCode);

    var objPds = new PagedDataSource();
    dr = cmd.ExecuteReader();// turn into an array
    dt.load(dr);

now you can do what you want with your datatable just call it like bellow

    objPds.DataSource = dt;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.