Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:11:13+00:00 2026-06-13T21:11:13+00:00

If I have a class called car and this car class uses a SQL

  • 0

If I have a class called “car” and this car class uses a SQL query to fill properties like ID, Name, Type, Model, Engine, and Size. How can I populate an asp:formview with that data?

I tried this:

Private currentCar As car        
fvCarview.DataSource = currentCar 
fvCarview.DataBind()

but I keep on getting this error:

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

Any help would be appreciated!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:11:15+00:00Added an answer on June 13, 2026 at 9:11 pm

    An easy way would be to use a List(Of Car) with a single car in it or a single IEnumerable(Car) via carList.Where(Function(c) c.ID = carID). You could also use a SqlDataAdapter to fill a DataTable and table.Where(Function(r) r.Field(Of Int32)("ID") = carID). Or just select the single car from database which is also the most efficiant way when you don’t need the complete list anyway:

    DataTable:

    Private Sub fillFormView(carID As Int32)
        Using con = New SqlConnection(My.Settings.SqlConnection)
            Using da = New SqlDataAdapter("SELECT ID, Name, Type, Model, Engine, Size FROM TCAR WHERE ID=@ID", con)
                da.SelectCommand.Parameters.AddWithValue("@ID", carID)
                Dim table = New DataTable
                da.Fill(table)
                fvCarview.DataSource = table
                fvCarview.DataBind()
            End Using
        End Using
    End Sub
    

    Here’s your custom Car-Class approach with a single car in a List(Of Car):

    Class Car
        Public Property ID As Int32
        Public Property Name As String
        Public Property Type As String
        Public Property Model As String
        Public Property Engine As String
        Public Property Size As Double
    End Class
    
    Private Sub fillFormView(carID As Int32)
        Using con = New SqlConnection(My.Settings.SqlConnection)
            Using cmd = New SqlCommand("SELECT ID, Name, Type, Model, Engine, Size FROM TCAR WHERE ID=@ID", con)
                cmd.Parameters.AddWithValue("@ID", carID)
                con.Open()
                Using rd = cmd.ExecuteReader()
                    rd.Read()
                    Dim carList = New List(Of Car)
                    Dim car = New Car()
                    car.ID = rd.GetInt32(0)
                    car.Name = rd.GetString(1)
                    car.Type = rd.GetString(2)
                    car.Model = rd.GetString(3)
                    car.Engine = rd.GetString(4)
                    car.Size = rd.GetDouble(5)
                    carList.Add(car)
                    fvCarview.DataSource = carList
                    fvCarview.DataBind()
                End Using
            End Using
        End Using
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Car class. It has three properties: id, color and model. In
If I have a list of objects called Car: public class Car { public
i have this class called MemoryManager, it is supposed to implement a simple smart
I have one class called Person that basically looks like: public class Person {
I have a scenario where a class called Comment references an abstract type called
We have small class, that has a related class class Car has_one :engine, :dependent
I have created a simple class called Engine which has an ivar called inputName
I have a Car class. It's got a property called enginePower. On the other
I have Class called Person containing to properties, Father and List of Children. I
I have a class called class Car , which has be instantiated as the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.