Solved

DataTableAdapters & Problems :-( .NET 2.0

Posted on 2006-06-23
5
263 Views
Last Modified: 2007-12-19
Hi,

I've been trying for over an hour to get this working, but I am stumped. So far, there are no errors, but it appears that the DataTable wont bind to the DataView. Even though there is a call to the SQL server, which gets the data (I've profled the server), nothing seems to tie up here :o(
I'm really startign to hate college work lol. But Please, if anyone can help me out here, I would really appreciate it.

Here is my code (all classes and the aspx/aspx/vb pages):

Imports Microsoft.VisualBasic

Public Class Contact
    Dim _ContactID As Integer
    Public Property ContactID() As Integer
        Get
            Return _ContactID
        End Get
        Set(ByVal value As Integer)
            _ContactID = value
        End Set
    End Property

    Dim _UserID As Integer
    Public Property UserID() As Integer
        Get
            Return _UserID
        End Get
        Set(ByVal value As Integer)
            _UserID = value
        End Set
    End Property

    Dim _BranchID As String
    Public Property BranchID() As Integer
        Get
            Return _BranchID
        End Get
        Set(ByVal value As Integer)
            _BranchID = value
        End Set
    End Property

    Dim _ContactTypeID As String
    Public Property ContactTypeID() As Integer
        Get
            Return _ContactTypeID
        End Get
        Set(ByVal value As Integer)
            _ContactTypeID = value
        End Set
    End Property

    Dim _Title As String
    Public Property Title() As String
        Get
            Return _Title
        End Get
        Set(ByVal value As String)
            _Title = value
        End Set
    End Property

    Dim _Firstname As String
    Public Property Firstname() As String
        Get
            Return _Firstname
        End Get
        Set(ByVal value As String)
            _Firstname = value
        End Set
    End Property

    Dim strInitials As String
    Public Property Initials() As String
        Get
            Return strInitials
        End Get
        Set(ByVal value As String)
            strInitials = value
        End Set
    End Property

    Dim _Surname As String
    Public Property Surname() As String
        Get
            Return _Surname
        End Get
        Set(ByVal value As String)
            _Surname = value
        End Set
    End Property

    Dim _DOB As Date
    Public Property DOB() As Nullable(Of Date)
        Get
            Return _DOB
        End Get
        Set(ByVal value As Nullable(Of Date))
            _DOB = value
        End Set
    End Property

    Dim _Gender As Boolean
    Public Property Gender() As Boolean
        Get
            Return _Gender
        End Get
        Set(ByVal value As Boolean)
            _Gender = value
        End Set
    End Property

    Dim _EMail As String
    Public Property EMail() As String
        Get
            Return _EMail
        End Get
        Set(ByVal value As String)
            _EMail = value
        End Set
    End Property

    Dim _Phone As String
    Public Property Phone() As String
        Get
            Return _Phone
        End Get
        Set(ByVal value As String)
            _Phone = value
        End Set
    End Property

    Dim _Mobile As String
    Public Property Mobile() As String
        Get
            Return _Mobile
        End Get
        Set(ByVal value As String)
            _Mobile = value
        End Set
    End Property
End Class


----------------------------------------------------------------------------------------------------------------------------------------------------------

Imports Microsoft.VisualBasic

Public Class ContactList
    Inherits System.ComponentModel.BindingList(Of Contact)
End Class

----------------------------------------------------------------------------------------------------------------------------------------------------------

Imports Microsoft.VisualBasic

Public Class Contacts
    Private Shared _contactsTableADapter As SCMDataSetsTableAdapters.tblContactsTableAdapter

    Shared Sub New()
        _contactsTableADapter = New SCMDataSetsTableAdapters.tblContactsTableAdapter
    End Sub

    Public Shared Function GetContactsListBySearch(ByVal SearchCriteria As String) As ContactList
        Dim ContactList As New ContactList
        Dim contactsDataTable As New SCMDataSets.tblContactsDataTable
        contactsDataTable = _contactsTableADapter.GetDataByListSearch(SearchCriteria, SearchCriteria, SearchCriteria)
        Return ConvertRowsToList(contactsDataTable)
    End Function

    Public Shared Function getAllContacts() As ContactList
        Dim ContactList As New ContactList
        Dim contactsDataTable As New SCMDataSets.tblContactsDataTable
        contactsDataTable = _contactsTableADapter.GetData
        Return ConvertRowsTolist(contactsDataTable)
    End Function

    Private Shared Function ConvertRowsToList(ByVal contactsDataTable As SCMDataSets.tblContactsDataTable) As ContactList
        Dim ContactList As New ContactList
        For Each contactRow As SCMDataSets.tblContactsRow In contactsDataTable
            Dim newContact As New Contact
            With newContact
                .ContactID = contactRow.pkContactsID
                If contactRow.IsfkUsersIDNull Then
                    .UserID = 0
                Else
                    .UserID = contactRow.fkUsersID
                End If
                .BranchID = contactRow.fkBranchesID
                .ContactTypeID = contactRow.fkContactsTypeID
                If contactRow.IstitleNull Then
                    .Title = Nothing
                Else
                    .Title = contactRow.title
                End If
                .Firstname = contactRow.firstName
                If contactRow.IsinitialsNull Then
                    .Initials = Nothing
                Else
                    .Initials = contactRow.initials
                End If
                .Surname = contactRow.surname

                If contactRow.IsdobNull Then
                    .DOB = Nothing
                Else
                    .DOB = contactRow.dob
                End If
                If contactRow.IsgenderNull Then
                    .Gender = False
                Else
                    .Gender = contactRow.gender
                End If
                If contactRow.IsemailNull Then
                    .EMail = Nothing
                Else
                    .EMail = contactRow.email
                End If
                If contactRow.IsphoneNull Then
                    .Phone = Nothing
                Else
                    .Phone = contactRow.phone
                End If
                If contactRow.IsmobileNull Then
                    .Mobile = Nothing
                Else
                    .Mobile = contactRow.mobile
                End If
            End With
        Next
    End Function
End Class

----------------------------------------------------------------------------------------------------------------------------------------------------------

In the ASPX form page I have the following:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
            <Columns>
                <asp:BoundField DataField="Initials" HeaderText="Initials" SortExpression="Initials" />
                <asp:BoundField DataField="EMail" HeaderText="EMail" SortExpression="EMail" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="ContactTypeID" HeaderText="ContactTypeID" SortExpression="ContactTypeID" />
                <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
                <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
                <asp:CheckBoxField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
                <asp:BoundField DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" />
                <asp:BoundField DataField="ContactID" HeaderText="ContactID" SortExpression="ContactID" />
                <asp:BoundField DataField="BranchID" HeaderText="BranchID" SortExpression="BranchID" />
                <asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="getAllContacts"
            TypeName="Contacts"></asp:ObjectDataSource>



and then this in te .aspx.vb codebehind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' GridView1.DataBind()
        Response.Write(getAllContacts.Count.ToString)
    End Sub







Any help on this would be much appreciated!

Thanks!

Adrian
0
Comment
Question by:pegasys
  • 2
5 Comments
 
LVL 25

Expert Comment

by:dstanley9
Comment Utility
You're not adding the new Contacts object to the list in GetAllContacts()
0
 
LVL 7

Author Comment

by:pegasys
Comment Utility
I thought I was?

I'm returning:  ConvertRowsTolist(contactsDataTable)

?? Can you give a small example of code what you mean?

Cheers

Adrian
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
Comment Utility
   Private Shared Function ConvertRowsToList(ByVal contactsDataTable As SCMDataSets.tblContactsDataTable) As ContactList
        Dim ContactList As New ContactList
        For Each contactRow As SCMDataSets.tblContactsRow In contactsDataTable
            Dim newContact As New Contact
            With newContact
                .ContactID = contactRow.pkContactsID
                If contactRow.IsfkUsersIDNull Then
                    .UserID = 0
                Else
                    .UserID = contactRow.fkUsersID
                End If

' snip

            End With

         ' Add this:
         ContactList.Add(newContact)

        Next
    End Function
End Class
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now