Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Moderators
Posted

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.

Visit...Bassic Software
Posted
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.
Posted

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.

  • 4 weeks later...
Posted
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?

Posted
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.

  • Moderators
Posted

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.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...