[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

reduce redundant data access code

Asked by llj45 in Programming for ASP.NET, Microsoft Visual Basic.Net, SQL Server 2008

Tags: asp.net ado.net vb.net

Hello,
  I find myself constantly using the code listed in a web based system which is currently under construction.  In the interest of reducing the use of the same code over and over, I wish to develop a class, function or sub or something which can be sent several parameters to do what the repetitive code does now.  These parameters would have to include the list of incoming "parameters" to the stored procedure.  Probably, there needs to be two different classes or whatever.  One class would return the results of SELECT statements.  The other class or whatever would return simply the record count or such indicating success from an INSERT, UPDATE or DELETE operation.
  The number of parameters going into the class or whatever varies.  So, perhaps, an array could be used to transport a flexible number of parameters to the stored procedure.

  Perhaps, there are good working examples on the Internet of how to do this work.
I am using ASP.NET 3.5, ADO.NET 3.5 and VB.NET with stored procedures in SQL Server 2008.
I don't need anything really elaborate just help me dramatically reduce the redundant code.  So, put the code in one place and call it again and again to work with the database.
Also, SQL datasource control on the aspx page doesn't work for me.
Thanks, LLJ45
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
SAMPLE 1 - SELECT
Dim SprocCommand As New SqlClient.SqlCommand
        Dim SprocConn As String = WebConfigurationManager.ConnectionStrings("RCD").ConnectionString
        Dim dcPlan As New SqlClient.SqlConnection(SprocConn)
        Dim daPlan As New SqlClient.SqlDataAdapter()
        Dim dsPlan As New DataSet
 
        Try
            SprocCommand.CommandType = CommandType.StoredProcedure
            SprocCommand.Connection = dcPlan
            SprocCommand.CommandText = "usp_plan_find_pin"
 
            Call SprocCommand.Parameters.Clear()
 
            'Create and append the parameters for the SELECT command
            Dim parmSSN As New SqlClient.SqlParameter("@SSN", Trim(txtSSN.Text))
            SprocCommand.Parameters.Add(parmSSN)
 
            Dim parmHPHONE As New SqlClient.SqlParameter("@HPHONE", Trim(txtHTelephone.Text))
            SprocCommand.Parameters.Add(parmHPHONE)
 
            Dim parmHZIP As New SqlClient.SqlParameter("@CERTNUM", Trim(txtCertNum.Text))
            SprocCommand.Parameters.Add(parmHZIP)
 
            If dcPlan.State <> ConnectionState.Open Then
                dcPlan.Open()
            End If
 
            daPlan.SelectCommand = SprocCommand
 
            dsPlan.Clear()
            daPlan.Fill(dsPlan)
 
            dcPlan.Close()
 
SAMPLE 2 - INSERT, UPDATE OR DELETE
                    Dim SprocCommand2 As New SqlClient.SqlCommand
                    Dim SprocConn2 As String = WebConfigurationManager.ConnectionStrings("RCD").ConnectionString
                    Dim dcPlan2 As New SqlClient.SqlConnection(SprocConn2)
                    Dim daPlan2 As New SqlClient.SqlDataAdapter()
 
                    ' get the info. needed to display the test
                    SprocCommand2.CommandType = CommandType.StoredProcedure
                    SprocCommand2.Connection = dcPlan2
                    SprocCommand2.CommandText = "usp_plan_save"
 
                    SprocCommand2.Parameters.Clear()
 
                    'Create and append the parameters for the SELECT command
                    Dim parmPIN2 As New SqlClient.SqlParameter("@PIN", Trim(Session("pr_pin")))
                    SprocCommand2.Parameters.Add(parmPIN2)
                    Dim parmID2 As New SqlClient.SqlParameter("@TESTID", Trim(Session("pr_TestID")))
                    SprocCommand2.Parameters.Add(parmID2)
                    Dim parmQuesID2 As New SqlClient.SqlParameter("@DISPLAYNUM", questionID)
                    SprocCommand2.Parameters.Add(parmQuesID2)
                    Dim parmChoiceID As New SqlClient.SqlParameter("@CHOICEID", choiceID)
                    SprocCommand2.Parameters.Add(parmChoiceID)
 
                    If dcPlan2.State <> ConnectionState.Open Then
                        dcPlan2.Open()
                    End If
 
                    SprocCommand2.ExecuteNonQuery()
 
                    dcPlan2.Close()
[+][-]11/04/09 07:06 PM, ID: 25746425Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Basic.Net, SQL Server 2008
Tags: asp.net ado.net vb.net
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: A
 
[+][-]10/30/09 11:40 AM, ID: 25705713Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 07:55 PM, ID: 25708157Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 10:00 AM, ID: 25710466Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 05:47 PM, ID: 25725512Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 07:44 PM, ID: 25725891Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 06:06 PM, ID: 25746158Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625