943,608 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 976
  • VB.NET RSS
Aug 14th, 2009
0

Access database in a class Constructor

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008
Aug 14th, 2009
0

Re: Access database in a class Constructor

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
Reputation Points: 23
Solved Threads: 10
Light Poster
bcasp is offline Offline
45 posts
since Apr 2008
Aug 16th, 2009
0

Re: Access database in a class Constructor

vb.net Syntax (Toggle Plain Text)
  1. public class DBClass
  2. ...
  3. public Function GetTable(Sql as String) as DataTable
  4. Dim Adp as new SqlDataAdapter(sql,CnStr)
  5. Dim Dt as New DataTable
  6. Adp.Fill(Dt)
  7. Return Dt
  8. End Function
  9.  
  10. End Class
  11. .....
  12. ....
  13. Dim cs as new DBClass
  14. Dim Ds as new DataSet("TestDS")
  15. Ds.Tables.Add(cs.getTable("Select * from Table1"),"Table1")
  16. ...
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Aug 17th, 2009
0

Re: Access database in a class Constructor

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jostra is offline Offline
12 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: dataview
Next Thread in VB.NET Forum Timeline: How can i detect that a object is from type enum?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC