0

I'm using asp.net based on VB.Net,

I want to access my Database and get the data, then I want to make list using that data.

An ASP GridView's style is not I want, so I decide to use another method.

So this is my code:

Dataget.vb

Public Shared Function GetData() As DataSet
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbsource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim query As String

    dbProvider = "PROVIDER=SQLOLEDB;"
    dbsource = "Data Source = ""
    con.ConnectionString = dbProvider & "Server="

    con.Open()
    query = "SELECT * FROM Table1"
    da = New OleDb.OleDbDataAdapter(query, con)
    da.Fill(ds, "Table1")

    con.Close()

    Return ds
End Function

**

And this is my ASP.Net page code.

**

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Master.Master" CodeBehind="List.aspx.vb" Inherits="WebApplication3.List1" %>

<%@ Import Namespace="WebApplication3" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div>
</div>

<form class="selection">
<ul class="list">
<%
    Dim ds As New Data.DataSet
    ds = DataGet.GetData()
    Dim title As String
    Dim counts As Integer = ds.Tables("Table1").Rows.Count - 1

    For i = 0 To counts
        title = ds.Tables("Table1").Rows(i).Item("title")
        Response.Write("<li a href='" & title & "'>" & title & "</a></li>")
    Next
%>
</ul>
</form>
</asp:Content>

I am retrieving the Data successfully, but I think this is a inefficient way to get the data.

So, my question is this.

I need a more efficient way, can you guys give me any advice?

Liath
  • 9,913
  • 9
  • 51
  • 81
Penguini
  • 11
  • 3
  • Did you try using the ListView control with a SQLDataSource? – Imad S. Feb 03 '14 at 13:20
  • 1
    Instead of selecting *, select just the fields you need. Also, your query does not have a where clause. That could result in the query returning more rows than you want. – Dan Bracuk Feb 03 '14 at 13:34

1 Answers1

0

write a stored procedure penguini it is much more efficient and it prevents sql injection

this explains what a stored procedure is and its benefits

What is a stored procedure?

this is just link on how to write one if the first link does not do the job but i am sure the first link is all that is needed

http://www.codeproject.com/Articles/126898/Sql-Server-How-to-write-a-Stored-procedure-in-Sql

Community
  • 1
  • 1
Wolf
  • 170
  • 1
  • 4
  • 19