By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

SQLConnection passing w/ user controls

P: n/a
Is better to pass the same SQL connection to all of my user controls.
Should I make a global object for my SQL connection, or is there some other
better choice out there.
Thanks

DG
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
David,

In my opinion is it simpler to make for your datahandling one or more
seperated classes.

The connection is than in that. The only things you are passing than is your
dataset (and what I do at the moment , the commands), the result can than be
error information. However there are a lot of ways to do this.

I hope this gives an idea

Cor

"David Gilbert" <da***@NOSPAM.cfsmortgage.com> schreef in bericht
news:eg**************@TK2MSFTNGP10.phx.gbl...
Is better to pass the same SQL connection to all of my user controls.
Should I make a global object for my SQL connection, or is there some
other better choice out there.
Thanks

DG

Nov 21 '05 #2

P: n/a
Ok just to put this in my own terms....

Create a class that has the instructions for my SQL connection and then open
and close, from there. This way If I change the Connection string, its only
in one place.

Thanks>...

DG
..... And the light bulb goes 'Click'
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
David,

In my opinion is it simpler to make for your datahandling one or more
seperated classes.

The connection is than in that. The only things you are passing than is
your dataset (and what I do at the moment , the commands), the result can
than be error information. However there are a lot of ways to do this.

I hope this gives an idea

Cor

"David Gilbert" <da***@NOSPAM.cfsmortgage.com> schreef in bericht
news:eg**************@TK2MSFTNGP10.phx.gbl...
Is better to pass the same SQL connection to all of my user controls.
Should I make a global object for my SQL connection, or is there some
other better choice out there.
Thanks

DG


Nov 21 '05 #3

P: n/a
Ok last question on this...

Know of any good books/websites on Classes?

"David Gilbert" <da***@NOSPAM.cfsmortgage.com> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Ok just to put this in my own terms....

Create a class that has the instructions for my SQL connection and then
open and close, from there. This way If I change the Connection string,
its only in one place.

Thanks>...

DG
.... And the light bulb goes 'Click'
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
David,

In my opinion is it simpler to make for your datahandling one or more
seperated classes.

The connection is than in that. The only things you are passing than is
your dataset (and what I do at the moment , the commands), the result can
than be error information. However there are a lot of ways to do this.

I hope this gives an idea

Cor

"David Gilbert" <da***@NOSPAM.cfsmortgage.com> schreef in bericht
news:eg**************@TK2MSFTNGP10.phx.gbl...
Is better to pass the same SQL connection to all of my user controls.
Should I make a global object for my SQL connection, or is there some
other better choice out there.
Thanks

DG



Nov 21 '05 #4

P: n/a
David,
Ok just to put this in my own terms....

Create a class that has the instructions for my SQL connection and then
open and close, from there. This way If I change the Connection string,
its only in one place.

No opening and closing is an unimportant part. When you use a dataadapter it
is even not needed.

However a sample, mostly typed, so watch typos or other things I typed
wrong.

\\\
Public Class DataClass
Public Function selectDS(mydataset, selectstring) As String
Dim frmSplash As New frmSplash
frmStatusMessage.Show("Connecting to SQL Server")
Dim conn As New SqlConnection(connString)
Try
Dim cmd As New SqlCommand (selectstring, conn)
da = New SqlDataAdapter(cmd)
dsMessages = New DataSet
da.Fill(mydataset)
Return ""
catch sqlExc As SqlException
return(sqlExc.ToString)
Catch ex As Exception
return(exc.Message)
Finally
conn.Close()
frmSplash.Close()
End Try
End Function
End Class
///

When you want it shared than the only thing that changes is
\\\
Public Shared Function selectDS(mydataset, selectstring) As String
///

I hope this gives some ideas

Cor
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.