How do you prefer to access/query data?

  • Thread starter Thread starter Cirene
  • Start date Start date
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!
 
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??? :)
 
Back
Top