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.

teferi2002

Technical User
Sep 24, 2005
81
US
I am not quite sure what this error msg is and how to fix it. can someone take a look at it give me a suggestion what i should do to take care of it. thanks


The IListSource does not contain any data sources.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The IListSource does not contain any data sources.

Source Error:


Line 19: dgr1.DataSource = oDataSet
Line 20: dgr1.DataMember = "Customers"
Line 21: dgr1.DataBind()
Line 22:
Line 23: End Sub






<%@Page Language="VB" EnableViewState="False" Debug="True" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>

<%-------------------------------------------------------------%>

<script runat="server">

' variable to hold reference to DataSet across routines
Dim oDataSet As DataSet

Sub Page_Load()

'fill the dataset with some rows from database
FillDataSet("c%")

' bind the data to the grid for display
dgr1.DataSource = oDataSet
dgr1.DataMember = "Customers"
dgr1.DataBind()

End Sub

<%-------------------------------------------------------------%>

Sub FillDataSet(sCustID As String)

' get DataSet with rows from Northwind tables

Dim sCustSql As String _
= "SELECT CustomerID, CompanyName, City, Country " _
& "FROM Customers WHERE CustomerID LIKE '" & sCustID & "'"
Dim sOrdersSql As String _
= "SELECT CustomerID, OrderID, OrderDate FROM Orders " _
& "WHERE CustomerID LIKE '" & sCustID & "'"
Dim sDetailsSql As String _
= "SELECT [Order Details].OrderID, Products.ProductID, " _
& "Products.ProductName, [Order Details].Quantity, " _
& "[Order Details].UnitPrice " _
& "FROM [Order Details] JOIN Products " _
& "ON [Order Details].ProductID = Products.ProductID " _
& "WHERE [Order Details].OrderID IN " _
& " (SELECT OrderID FROM Orders " _
& " WHERE CustomerID LIKE '" & sCustID & "')"





Dim sConnect As New OleDbConnection("provider=Microsoft.jet.OleDb.4.0;Data Source=c:\Nwind.mdb" )

oDataSet = New DataSet()

Try

' fill DataSet with three tables
Dim oDA As New OleDbDataAdapter(sCustSQL, sConnect)
sConnect.Open()
oDA.Fill(oDataSet, "Customers")
oDA.SelectCommand.CommandText = sOrdersSql
oDA.Fill(oDataSet, "Orders")
oDA.SelectCommand.CommandText = sDetailsSql
oDA.Fill(oDataSet, "OrderDetails")
sConnect.Close()

' create relations between the tables
Dim oRel As New DataRelation("CustOrders", _
oDataSet.Tables("Customers").Columns("CustomerID"), _
oDataSet.Tables("Orders").Columns("CustomerID"))
oDataSet.Relations.Add(oRel)
oRel = New DataRelation("OrdersODetails", _
oDataSet.Tables("Orders").Columns("OrderID"), _
oDataSet.Tables("OrderDetails").Columns("OrderID"))
oDataSet.Relations.Add(oRel)

Catch oErr As Exception

' be sure to close connection if error occurs
If sConnect.State <> ConnectionState.Closed Then
sConnect.Close()
End If

' display error message in page
lblErr.Text = oErr.Message

End Try

End Sub

</script>

<%-------------------------------------------------------------%>
<%-------------------------------------------------------------%>

<html>
<head>
<title>Declarative Nested Binding to a DataSet</title>
</head>
<body>

<span class="heading">Declarative Nested Binding to a DataSet</span><hr />

<form runat="server">

<asp:Label id="lblErr" EnableViewState="False" runat="server" /><p />

<asp:DataGrid id="dgr1" runat="server"
Font-Size="10" Font-Name="Tahoma,Arial,Helvetica,sans-serif"
BorderStyle="None" BorderWidth="1px" BorderColor="#deba84"
BackColor="#DEBA84" CellPadding="5" CellSpacing="1"
AutoGenerateColumns="False"
>
<HeaderStyle Font-Bold="True" ForeColor="#ffffff" BackColor="#b50055" />
<ItemStyle BackColor="#FFF7E7" VerticalAlign="Top" />
<AlternatingItemStyle backcolor="#ffffc0" />
<Columns>
<asp:TemplateColumn HeaderText="Customer Details">
<ItemTemplate>
<b><%# Container.DataItem("CompanyName") %></b><br />
City: <%# Container.DataItem("City") %><br />
Country: <%# Container.DataItem("Country") %><br />
CustomerID: "<%# Container.DataItem("CustomerID") %>"
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order History">
<ItemTemplate>

<asp:DataGrid id="dgr2" runat="server"
BorderStyle="None" BorderWidth="0" BackColor="#deba84"
CellPadding="5" CellSpacing="2" Width="100%"
AutoGenerateColumns="False"
DataSource='<%# CType(Container.DataItem,DataRowView).CreateChildView("CustOrders") %>'
>
<HeaderStyle BackColor="#c0c0c0" />
<ItemStyle Font-Bold="True" VerticalAlign="Top" />
<Columns>
<asp:BoundColumn DataField="OrderID" HeaderText="Number" />
<asp:TemplateColumn HeaderText="Details">
<ItemTemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, _
"OrderDate", "{0:dddd dd MMM yyyy}") %>' />

<asp:DataGrid id="dgr3" runat="server"
BorderStyle="None" BorderWidth="0"
CellPadding="3" CellSpacing="0" Width="100%"
AutoGenerateColumns="False"
DataSource='<%# CType(Container.DataItem,DataRowView).CreateChildView("OrdersODetails") %>'
>
<HeaderStyle BackColor="#c0c0c0" />
<Columns>
<asp:BoundColumn DataField="ProductID"
HeaderText="ID" />
<asp:BoundColumn DataField="ProductName"
HeaderText="Product" />
<asp:BoundColumn DataField="Quantity"
ItemStyle-HorizontalAlign="Right"
HeaderStyle-HorizontalAlign="Right"
HeaderText="Qty" />
<asp:BoundColumn DataField="UnitPrice"
DataFormatString="${0:f2}"
ItemStyle-HorizontalAlign="Right"
HeaderStyle-HorizontalAlign="Right"
HeaderText="Price"/>
</Columns>
</asp:DataGrid>

</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

</form>

<span class="cite">
Remember to edit the connection strings in your web.config
file for the Northwind sample database.
</span>
<hr />


</body>
</html>


 
I am pretty sure that there is someone who has an idea where this error is coming form.please take a look at it give me a clue. thanks for your time and help
 
Please don't be impatient - Tek-Tips is not a helpdesk.

As for your error, the DataSet is most probably empty or you need to set it to a specific table e.g.
Code:
DataGrid1.DataSource = ds.Tables("myTable")


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sorry if i sound like i am being impatient.Thank you ca8msm for your reply..I will work on that and let you know the outcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top