Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The IListSource does not contain any data sources

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
I am getting the error The 'IListSource does not contain any data sources' on the DataBind line in my code below. I have stepped through and there are records in the data reader...in fact this code has been working for over a year and has just now starting to give this error. Can anybody help?

private void BindData()
{
string strLeadAssignmentCount = "";

SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["constr"]);
objConnection.Open();

//get row count
switch (intJobRoleKey)
{
//admin
case 2:
strLeadAssignmentCount = "select count(*) ";
strLeadAssignmentCount += "from atradius_staging where assigned = 0";
break;

//CI
case 5:
strLeadAssignmentCount = "select count(*) ";
strLeadAssignmentCount += "from atradius_staging where assigned = 0 and leadtypekey = 1";
break;

//DC
case 6:
strLeadAssignmentCount = "select count(*) ";
strLeadAssignmentCount += "from atradius_staging where assigned = 0 and leadtypekey = 2";
break;

//Brokers
case 7:
strLeadAssignmentCount = "select count(*) ";
strLeadAssignmentCount += "from atradius_staging where assigned = 0 and leadtypekey = 3";
break;

default:
Response.Redirect("default.aspx");
break;
}

SqlCommand objCommandCount = new SqlCommand(strLeadAssignmentCount, objConnection);
int intTotalRows = Convert.ToInt32(objCommandCount.ExecuteScalar());

if (intTotalRows > 0)
{
//now populate datareader with actual data
SqlCommand objCommand = new SqlCommand("LeadAssignmentList", objConnection);
objCommand.CommandType = CommandType.StoredProcedure;

SqlParameter prmJobRoleKey = new SqlParameter("@JobRoleKey", SqlDbType.Int, 4);
prmJobRoleKey.Value = intJobRoleKey;
objCommand.Parameters.Add(prmJobRoleKey);

// try
// {
SqlDataReader result = objCommand.ExecuteReader(CommandBehavior.CloseConnection);

//populate datagrid
dgLeadAssignment.DataSource = result;
dgLeadAssignment.DataBind();

GetUserList();
imgKey.Visible = true;
btnAssignLeads.Visible = true;
dgLeadAssignment.Visible = true;
// }
// catch
// {
// }
}
else
{
imgKey.Visible = false;
btnAssignLeads.Visible = false;
dgLeadAssignment.Visible = false;
lblTotalUnassigned.Text = "Total unassigned leads : " + intTotalRows.ToString();
}
 
If your data connection is being closed as soon as the reader is executed, then surely you are binding to a reader that contains nothing?

try removing the CommandBehavior.CloseConnection ?

K
 
I found the error...it wasn't anything to do with the code that I posted, it was a matter of a stored proc that was being used to populate one of the fields of the data grid being changed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top