Solved

Building a common library for .Net Applications

Posted on 2014-03-17
3
264 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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