Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:14:46+00:00 2026-05-18T08:14:46+00:00

Hi someone can help me here. How will this code look like if using

  • 0

Hi someone can help me here.

How will this code look like if using ORM connection

Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Public Sub OpenDBproduct()
        Dim ProductConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

        Dim ProductReader As SqlDataReader
        Dim ProductCommand As SqlCommand

        Dim ProductSQL As String = ""
        ProductSQL = "SELECT * FROM table1 ORDER BY PName DESC;"
        ProductCommand = New SqlCommand(ProductSQL, ProductConnection)

        'Prøv at åben Connection.
        Try
            ProductConnection.Open()
            ProductReader = ProductCommand.ExecuteReader(CommandBehavior.CloseConnection)
            'Hvis der er data, udskriv da dataen.
            If ProductReader.HasRows() Then

                Response.Write("<h2>Produkter</h2>")
                Response.Write("<table style=""width:340px; border:0px;""><tr>")

                Do While ProductReader.Read()
                    Response.Write("<td colspan=""3""><br /></td>")
                    Response.Write("</tr><tr>")
                    Response.Write("<td style=""width:10px;""></td>")
                    Response.Write("<td><div style=""width:52px; text-align:center;""><span class=""""># " & ProductReader("PName") & "</span></div></td>")
                    Response.Write("<td class=""""><span class="""">" & ProductReader("PName") & "</span><br /><span class="""">" & ProductReader("PPrice") & "</span><br /><span class=""""><b>" & ProductReader("Pean") & "</b></span></td>")
                    Response.Write("</tr><tr>")
                    Response.Write("<td colspan=""3""><br />" & ProductReader("PDescription") & "</td>")
                    Response.Write("</tr><tr>")
                    Response.Write("<td style=""border-bottom:dashed 2px #FFA902;"" colspan=""3""><br /></td>")
                    Response.Write("</tr><tr>")

                Loop
                Response.Write("</tr></table>")
                Response.Write("Slutning")
            Else
                'Hvis der ikke er data, lav en fejl tekst.
                Response.Write("<table style=""width:340px; border:0px;""><tr><td>")
                Response.Write("Der findes ingen produkter.")
                Response.Write("<br /><br />")
                Response.Write("Slutning")
                Response.Write("</td></tr></table>")
            End If

        Catch ex As Exception
            Console.WriteLine(ex.Message)

        Finally
            'Lukker Connection, Reader og Sletter Hukommelse.
            If Not ProductReader Is Nothing Then
                ProductReader.Dispose()
            End If
            If Not ProductConnection Is Nothing Then
                ProductConnection.Dispose()
            End If

        End Try
    End Sub
End Class 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:14:46+00:00Added an answer on May 18, 2026 at 8:14 am

    If I understood you right – you ask about changes no that code if you use some ORM, like EntityFramework or NHibernate.
    So short description is (sorry for C# syntax):
    connecting will change to strongly typed code, without SQL string.

    using (var dbContext = new ProductEntites())
    {
       var dbSelect = dbContext.Products.OrderBy(x=>x.PName);
    

    Do-While will be changed to foreach(var product in dbSelect)

    All ProductReader("PDescription") would be changed to product.PDescription (no strings!)

    Using ORM

    • it’s much safer to use all profits of strongly typed classes (they will be generated with Visual Studio tools)
    • parameter checks for SQL-injections are mede automatically
    • is highly recommended if you need to create DB-independant application
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a follow-up to this question I am hoping someone can help with the
Ok, this is bit of an obscure question, but hopefully someone can help me
Can someone help me identify what the purpose of this unidentified syntax is. It
I am pretty new to javascript so I hope someone here can help me
I am wondering if someone can help me figure out the best approach to
I've never been much for math and I'm hoping that someone can help me
Slightly strange question, but hopefully someone can help. In essence, if the time was
Can someone help me figure out the following make file? BINS=file1 file2 file3 all:
Can someone help explain the following: If I type: a=`ls -l` Then the output
Can someone help me with the getopt function? When I do the following in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.