467,074 Members | 895 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

How do you prefer to access/query data?

I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)

Typically I write a simple Stored Procedure, then access it from my webform
like this...

Dim MyConnection As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("ConnectionString").ToString)
MyConnection.Open()

Dim MyCommand As SqlCommand
Try
MyCommand = New SqlCommand("GetTimesFlaggedByThisUser",
MyConnection)
MyCommand.CommandType = Data.CommandType.StoredProcedure
MyCommand.Parameters.AddWithValue("@PostingId",
Request.QueryString("Id"))
MyCommand.Parameters.AddWithValue("@PostTitle", lblTitle.Text)
MyCommand.Parameters.AddWithValue("@FlaggedById",
Membership.GetUser(HttpContext.Current.User.Identi ty.Name.ToString).ProviderUserKey.ToString)
i = MyCommand.ExecuteScalar
Catch ex As Exception
lblStatus.Text = "ERROR WITH GetTimesFlaggedByThisUser: " &
ex.ToString
Exit Sub
Finally
MyConnection.Close()
End Try

I find that much of the code is redundant - the connection, declaring the
sqlcommand, the catch ex, etc...

Where do you all put this type/level of code? Do you usually just drop it
in a class/business object and access it like MyObj.GetTimesFlagged ?

Any suggestions. I'm always looking to do things better and using the more
"suggested" method.

Thanks!
Jul 31 '08 #1
  • viewed: 1271
Share:
4 Replies
"Cirene" <ci****@nowhere.comwrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
>I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)
Direct SQL statements should be avoided - do a Google for "SQL Injection"...
Any suggestions. I'm always looking to do things better and using the
more "suggested" method.
I have a lightweight DAL which I drop into any project which needs database
connectivity. It works unmodified with both WinForms and WebForms projects,
and currently supports SQL Server (Express), SqlCe, Oracle and MySQL using a
factory pattern. Support for RDMBS can be added as required.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 31 '08 #2
Is this like the Enterprise Library Data Access that's available?

Is there a DAL I can download so I don't have to create it?

Or, perhaps I can email you directly and can use yours??? :)

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Cirene" <ci****@nowhere.comwrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
>>I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)

Direct SQL statements should be avoided - do a Google for "SQL
Injection"...
>Any suggestions. I'm always looking to do things better and using the
more "suggested" method.

I have a lightweight DAL which I drop into any project which needs
database connectivity. It works unmodified with both WinForms and WebForms
projects, and currently supports SQL Server (Express), SqlCe, Oracle and
MySQL using a factory pattern. Support for RDMBS can be added as required.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 31 '08 #3
"Cirene" <ci****@nowhere.comwrote in message
news:um*************@TK2MSFTNGP02.phx.gbl...

[top-posting corrected]
>>>I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)

Direct SQL statements should be avoided - do a Google for "SQL
Injection"...
>>Any suggestions. I'm always looking to do things better and using the
more "suggested" method.

I have a lightweight DAL which I drop into any project which needs
database connectivity. It works unmodified with both WinForms and
WebForms projects, and currently supports SQL Server (Express), SqlCe,
Oracle and MySQL using a factory pattern. Support for RDMBS can be added
as required.

Is this like the Enterprise Library Data Access that's available?
It was based on it...
Is there a DAL I can download so I don't have to create it?
http://www.microsoft.com/downloads/d...displaylang=en
Or, perhaps I can email you directly and can use yours??? :)
'Fraid not...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 31 '08 #4
Thanks!

I guess the Enterprise Library DAAB is the new one.

http://aspalliance.com/688

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:us****************@TK2MSFTNGP06.phx.gbl...
"Cirene" <ci****@nowhere.comwrote in message
news:um*************@TK2MSFTNGP02.phx.gbl...

[top-posting corrected]
>>>>I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)

Direct SQL statements should be avoided - do a Google for "SQL
Injection"...

Any suggestions. I'm always looking to do things better and using the
more "suggested" method.

I have a lightweight DAL which I drop into any project which needs
database connectivity. It works unmodified with both WinForms and
WebForms projects, and currently supports SQL Server (Express), SqlCe,
Oracle and MySQL using a factory pattern. Support for RDMBS can be added
as required.

Is this like the Enterprise Library Data Access that's available?

It was based on it...
>Is there a DAL I can download so I don't have to create it?

http://www.microsoft.com/downloads/d...displaylang=en
>Or, perhaps I can email you directly and can use yours??? :)

'Fraid not...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 1 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Frnak McKenney | last post: by
14 posts views Thread by Sean C. | last post: by
52 posts views Thread by Neil | last post: by
4 posts views Thread by Takeadoe | last post: by
1 post views Thread by smaczylo@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.