Row Count: What am I doing wrong?

Row Count: What am I doing wrong?

Post by David Fric » Tue, 25 Mar 2003 01:35:51



When I add  the following line to a form with a DataList control:

<%# CType(DataList1.DataSource, DataView).Count.ToString() + " employees
found."%>

I get the error:  Compiler Error Message: BC30002: Type 'DataView' is not
defined.

What am I doing wrong?

I set the following references:

    Imports System.Data
    Imports System.Data.SqlClient

And I access my data as:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim sCn As String = "DATABASE=Northwind; " & _
        "SERVER=localhost;Trusted_Connection=yes"
        Dim sCmd As String = "SELECT employeeid, firstname, " & _
            "lastname FROM Employees"

        Dim cn As New SqlConnection(sCn)
        Dim da As New SqlDataAdapter(sCmd, cn)

        Dim ds As DataSet = New DataSet()
        da.Fill(ds, "MyTable")

        DataList1.DataSource = ds.Tables("MyTable").DefaultView
        DataList1.DataBind()

    End Sub

I can read my field values just fine as:

<%# DataBinder.Eval(Container.DataItem,"LastName") %>

But why does it *on:

<%# CType(DataList1.DataSource, DataView).Count.ToString() + " employees
found."%>

I thought appending the "DefaultView" to my data source would define a "Type
'DataView' " but apparently it is not recognized.

Thanks for any ideas.
Dave

 
 
 

Row Count: What am I doing wrong?

Post by Kathleen Dollar » Tue, 25 Mar 2003 07:28:31


David,

You're close...

A type is a class in this context.

This is an Imports problem. All Imports (and one of the two ambigous usages
of the word "using" in C#) does is supply a typing short cut. This typing
shortcut is file specific, and I don't know a way to use it in ASP.NET. Thus

Quote:> <%# CType(DataList1.DataSource, DataView).Count.ToString() + " employees
> found."%>

Should be

Quote:> <%# CType(DataList1.DataSource, System.Data.DataView).Count.ToString() + "
employees
> found."%>

because otherwise, the class DataView can't be seen in this context.

Let me know if that doesn't fix your problem.

Kathleen


Quote:> When I add  the following line to a form with a DataList control:

> <%# CType(DataList1.DataSource, DataView).Count.ToString() + " employees
> found."%>

> I get the error:  Compiler Error Message: BC30002: Type 'DataView' is not
> defined.

> What am I doing wrong?

> I set the following references:

>     Imports System.Data
>     Imports System.Data.SqlClient

> And I access my data as:

>     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load

>         Dim sCn As String = "DATABASE=Northwind; " & _
>         "SERVER=localhost;Trusted_Connection=yes"
>         Dim sCmd As String = "SELECT employeeid, firstname, " & _
>             "lastname FROM Employees"

>         Dim cn As New SqlConnection(sCn)
>         Dim da As New SqlDataAdapter(sCmd, cn)

>         Dim ds As DataSet = New DataSet()
>         da.Fill(ds, "MyTable")

>         DataList1.DataSource = ds.Tables("MyTable").DefaultView
>         DataList1.DataBind()

>     End Sub

> I can read my field values just fine as:

> <%# DataBinder.Eval(Container.DataItem,"LastName") %>

> But why does it *on:

> <%# CType(DataList1.DataSource, DataView).Count.ToString() + " employees
> found."%>

> I thought appending the "DefaultView" to my data source would define a
"Type
> 'DataView' " but apparently it is not recognized.

> Thanks for any ideas.
> Dave


 
 
 

1. What am i doing wrong????

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30684: The name 'DataRowView' is declared as a
type, and so cannot be used as an expression.

Source Error:

Line 33:                                        </B>
Line 34:                                        <BR>
Line 35:                                        <asp:repeater id="Repeater1" runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("myrelation")
%>'><ITEMTEMPLATE>
Line 36:                                                        <%# ((DataRow)Container.DataItem)[1] %>
Line 37:

2. Last version of IDL supported on VAX/VMS?

3. What am I doing wrong?

4. COM interop registration failure

5. PDAWIN and Large CCF Files

6. Am I doing something wrong or is this a bug in GDI+

7. Follow our Jobs on Blogger

8. What am I doing wrong?

9. Trying to search and retrieve specific nodes... what am i doing wrong

10. what am i doing wrong with this datagrid or VB.NET or XML ?

11. What am I doing wrong? (XSLT question)

12. What am I doing wrong?