Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.

Simflex 301 Reputation points
2022-12-28T16:37:13.687+00:00

Greetings again.

Hoping to get a quick solution from you experts.

I am still working on converting our app from LINQ to 'regular' asp.net code.

The following is the LINQ I am trying to convert:

                var iaddresses = from a in Addresses  
                                 where a.Address.StartsWith(streetAddress.Text.Trim())  
                                 select a;  

                if (iaddresses.Count() == 0)  
                {  

                    // get the address data from the user  
                    Address.Text = Master.textInfo.ToTitleCase(streetAddress.Text.Trim());  

                }  
                else if (iaddresses.Count() > 1)  
                {  

                    // set the DataSource, Bind it and show the MPE  
                    grv.DataSource = iaddresses;  
                    grv.DataBind();  

Below is my rewrite of the code in vb.net:

              myConnection.Open()  
                 Dim cmd As New SqlCommand(" SELECT * From Addresses Where InstallAddress LIKE '" & streetAddress.Text.Trim() & "%'", myConnection)  
                 Dim intCount As Integer = CType(cmd.ExecuteScalar, Integer)  
 
                 If intCount = 0 Then  

                     'get the address data from the user  
                     Address.Text = textInfo.ToTitleCase(streetAddress.Text.Trim())  

                 ElseIf intCount > 1 Then  

                     grv.DataSource = intCount ***'<-- error here***  
                     grv.DataBind()  

However, I am getting the following error:

Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.

A majority of the LINQ code is written similarly to above. Getting this to work is really going to help with most of the remaining.

I have an arrow pointing to the offending line.

Many thanks in advance.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Simflex 301 Reputation points
    2022-12-28T17:07:02.023+00:00

    Ok, I think I solved it, sorry guys.

    Here is the modified snip:

                     Dim dt As Datatale = New Datatable  
                     myConnection.Open()  
                     Dim sqlstmt = " SELECT * From Addresses Where InstallAddress LIKE '" & streetAddress.Text.Trim() & "%'"  
                     Dim sqlcmd As SqlCommand(sqlstmt, myConnection)  
                     Dim sqlDa As SqlAdapter = New SqlAdapter(sqlcmd)  
     
                     If dt.Rows.Count = 0 Then  
    
                         'get the address data from the user  
                         Address.Text = textInfo.ToTitleCase(streetAddress.Text.Trim())  
    
                     ElseIf dt.Rows.Count > 1 Then  
    
                         grv.DataSource = dt '<-- replaced intCount with dt and it solved the problem.  
                         grv.DataBind()  
    
    0 comments No comments