tags:

views:

596

answers:

1

Hi , i am a newbie at ASP.net and after using sqldatasource with a listview to insert and show results from an SQL server db i want to try using the LINQ datasource since it seems to be more flexible in codebehind. My problem is this: i droped a listview control to the page and i created the Linq datasource in codebehind with vb. the issue that i am having when i ..Select d.columms name i get the error system.string does not contain a property with the name "columname".. if i ommit the column name then its works fine.. the funny part is the d.count works fine but after that i get the error.. please see my code below:

vb code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim rowsCount As Integer
    Dim showSearchForm As String
    showSearchForm = Request.QueryString("tab")
    If showSearchForm = "1" Then
        Dim db As New ASPNETDBDataContext()
        Dim q = From b In db.PassengerVehiclesTables Select b.dbMake
        rowsCount = q.Count
        MsgBox(rowsCount)
        lvMakes.DataSource = q
        lvMakes.DataBind()
        PnlPassengerVehiclesSearch.Visible = True
    ElseIf showSearchForm = "2" Then

aspx code

<asp:Panel ID="PnlPassengerVehiclesSearch" Visible="false" runat="server">
    Search Passenger Vehicles Form.....<br />
    <table style="width: 100%; border-style: solid; border-width: 1px">
        <tr>
            <td>
                <asp:ListView ID="lvMakes" runat="server">
                    <LayoutTemplate>
                        <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
                    </LayoutTemplate>
                    <ItemTemplate>
                        <%#Eval("dbMake")%><br />
                    </ItemTemplate>
                </asp:ListView>
            </td>

b.dbMake needs to work so that i can use Distinct ,, ia m using asp.net version:3.5 and IIS version 7.0 .. not sure what i am missing ,, but i did try alot of approaches,,1- checked the web.config file and it seems to have two assemblies and two namespaces for LINQ..2- used different databinding syntaxs,,and i searched a lot for the solution.. the last one i read the person ommited the name of the column,, i thought that wasnt the best solution.. also my dbMake column is comming up in the "intellisence" .. thank you in advance for your help..

A: 

change the following

 Dim q = From b In db.PassengerVehiclesTables Select b.dbMake

to

 Dim q = From b In db.PassengerVehiclesTables Select New With {b.dbMake}

For further explanation see http://stackoverflow.com/questions/2263242/select-new-keyword-combination

Art