Solved

Building a common library for .Net Applications

Posted on 2014-03-17
3
270 Views
Last Modified: 2014-03-24
Hi guys,

I am jumping into the world of OOP. For start can you please advise me in building a library  which contains classes like connection string  and open close, Classes which return update, insert and delete query, classes which return list<t> or data sets. I am looking to build this library generic to use with different applications.

kindest regards,
0
Comment
Question by:shah36
[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
3 Comments
 
LVL 1

Expert Comment

by:Lucky Ncube
ID: 39934034
Here is an example of how I do it using Classes.
1. Define class called tblCIty to present my database table called tblCIty. Please note that this is an instantiating class
Public Class tblCity

    Property CityID As Guid
    Property City As String

    Sub New()

    End Sub
    Sub New(ByVal sqlRdr As SqlDataReader)
        _CityID = sqlRdr("CityID")
        _City = sqlRdr("City")
    End Sub
    Public Overrides Function ToString() As String
        Return _City
    End Function

End Class

Open in new window


After I have by class I can use the class to now list the Cities by add them to the List as Shown Below:
Public Shared Function List(ByVal sqlConn As SqlConnection, Optional ByVal sqlTrans As SqlTransaction = Nothing) As List(Of tblCity)
        Dim iList As New List(Of tblCity)
        Using sqlCmd As New SqlCommand("City_List", sqlConn, sqlTrans)
            sqlCmd.CommandType = CommandType.StoredProcedure
            Using sqlRdr As SqlDataReader = sqlCmd.ExecuteReader
                While sqlRdr.Read
                    iList.Add(New tblCity(sqlRdr))
                End While
                sqlRdr.Close()
            End Using
        End Using
        Return iList
    End Function

Open in new window

This  simple object manipulating code.
0
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 39934407
This kind of thing has been done a lot. Your question doesn't have any easy or simple one-page answer. First, I would direct you to libraries that already exist that provide for this functionality in the .NET framework. Mainly, the Entity Framework:
http://msdn.microsoft.com/en-us/data/ef.aspx

Otherwise, a simple web search on ".net c# crud framework" will give you a bunch of options to choose from.
0
 

Author Closing Comment

by:shah36
ID: 39950535
Thanks gave me the start
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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