drewex Posted October 28, 2003 Posted October 28, 2003 Hi all I'm new in asp.net (old asp programmer) 1. In asp i had a page that hold the database connections stuff. And i had included it to the page like this; <!--#INCLUDE file="DBLib.asp" --> Now im want to do same thing but its and object or something. Do i have to create a connection all the time is there a better way. 2. And statements i was using lines of sql querys to get stuff. And when something had to change got in the code and changed it. In .net do i have to do it using the wizard or is there a way to change it while the program runs or from the code or something. I'm open to all solutions. I know there should be alot of ways doing it so If you have a different way to it. I like to see that. Thanks Quote
Moderators Robby Posted October 28, 2003 Moderators Posted October 28, 2003 You can create a class that can be reused by any page that requires database interaction, webForms and winForms will be able to use it. This class can return whatever you may need, Datasets, Dataviews, Scalars, ExecuteNonQueries, etc... I would leave all the SQL Select statements in the class (let's say Business Layer) that inherits or instantiates the database class. Quote Visit...Bassic Software
drewex Posted October 28, 2003 Author Posted October 28, 2003 thanks that a good way that i want to learn. But Im not good with classes. If you can give a example. like making a connection and setting the datagrid to it using the class. lIke sending parameters or something is there a tutorial that i could look or some examples. Quote
bungpeng Posted October 29, 2003 Posted October 29, 2003 Just a normal class Public Class DBlayer Public Shared Function GetConnectionStr return "..." End Function End Class For "Shared" function, you can direct use this function without using object. Quote
Muhad Posted November 20, 2003 Posted November 20, 2003 You can create a class that can be reused by any page that requires database interaction, webForms and winForms will be able to use it. This class can return whatever you may need, Datasets, Dataviews, Scalars, ExecuteNonQueries, etc... I would leave all the SQL Select statements in the class (let's say Business Layer) that inherits or instantiates the database class. Any chance you could post the class code file here for us to download? Quote
Administrators PlausiblyDamp Posted November 20, 2003 Administrators Posted November 20, 2003 I think Robby meant he would write a class that encapsulated His Database logic for a particular system - not a class that would encapsulate all database access. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Muhad Posted November 20, 2003 Posted November 20, 2003 I think Robby meant he would write a class that encapsulated His Database logic for a particular system - not a class that would encapsulate all database access. I would like to see the code to learn how to set up the class. It would be a great example. Quote
Moderators Robby Posted November 20, 2003 Moderators Posted November 20, 2003 It's just generic stuff, there can be methods for returning Dataset, Arrays, ExecuteNonQueries, ExecuteScalar etc... Create a class; make it abstract or virtual, also it's up to you if you want to hard-code your connection string or not. Do not place any SQL statements or business logic in this class. Once you set this up you will never have to fill dataAdapters, DataSets, etc, in your client code. Sorry but I will not provide any sample code for this. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.