954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Access database in a class Constructor

Hi! everyone can some one share a piece of light with me is it possible to manipulate database access inside a class constructor.Cause i can create a connection but don't know how i'm going to things like data adapter an data set since.Any link Any Help Is appreciated.thanks

Jostra
Newbie Poster
12 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

It would probably be possible, but I would probably rethink why there are database calls inside of the constructor. I would rather split it out into a separate call.

Here's a link to a Microsoft Patterns and Practices article. If it can't answer questions about how to handle database connectivity then I don't know what will:

http://msdn.microsoft.com/en-us/library/ms978510.aspx

bcasp
Light Poster
46 posts since Apr 2008
Reputation Points: 23
Solved Threads: 10
 
public class DBClass
     ... 
     public Function GetTable(Sql as String) as DataTable
         Dim Adp as new SqlDataAdapter(sql,CnStr)
         Dim  Dt as New DataTable
         Adp.Fill(Dt)
         Return Dt
     End Function

End Class
.....
....
Dim cs as new DBClass
Dim Ds as new DataSet("TestDS")
Ds.Tables.Add(cs.getTable("Select * from Table1"),"Table1")
...
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Thanks adapost i truly didnt know this like i said on my thread, can you please explain to me how do i define an adapter in a class. i appreciate thank

Jostra
Newbie Poster
12 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You