How do you prefer to access/query data?

C

Cirene

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.ConnectionStrings("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.Identity.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!
 
C

Cirene

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??? :)
 
C

Cirene

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top