Access database in a class Constructor

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Access database in a class Constructor

 
0
  #1
Aug 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: bcasp is an unknown quantity at this point 
Solved Threads: 10
bcasp bcasp is offline Offline
Light Poster

Re: Access database in a class Constructor

 
0
  #2
Aug 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 500
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Access database in a class Constructor

 
0
  #3
Aug 16th, 2009
  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. ...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: Jostra is an unknown quantity at this point 
Solved Threads: 0
Jostra Jostra is offline Offline
Newbie Poster

Re: Access database in a class Constructor

 
0
  #4
Aug 17th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC