Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataTableAdapters & Problems :-( .NET 2.0

Posted on 2006-06-23
5
Medium Priority
?
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 25

Expert Comment

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

Author Comment

by:pegasys
ID: 16974314
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 2000 total points
ID: 16984350
   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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

609 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