Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need to read some data from a DB

Posted on 2005-04-13
3
Medium Priority
?
170 Views
Last Modified: 2010-04-07
I need to read a filed on my DB where I have some content for my website.
I would like to know what is the best way to call and get the information.

the information on the DB is the text for the website.
0
Comment
Question by:Enniobozzetti
  • 2
3 Comments
 

Author Comment

by:Enniobozzetti
ID: 13775848
here is my code.


<script language="vbscript" runat="server">
'******************************************
'*    DB CONNECTION On page_load          *
'******************************************
Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
      Dim myConn As OleDbConnection
      myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("/database/ebdizin.mdb") & ";")
      myConn.Open()
End Sub

'******************************************
'* Read the content from the DB           *
'******************************************
Private Function read_content()
      Dim myComm As OleDbCommand
      myComm = New OleDbCommand("SELECT * FROM tbl_content WHERE id=1")
    Response.Write("The function call worked.")
End Function
</script>
0
 
LVL 4

Accepted Solution

by:
vladimir_kalashnikov earned 500 total points
ID: 13776896
ummm, that isn't really the best way to do it.  first of all, you just leave a connection open when the page loads.  you don't even get any info from it.  weird.  here is a better way to do it.

Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
     Dim myConn As OleDbConnection
     myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("/database/ebdizin.mdb") & ";")

     Dim myComm As OleDbCommand
     myComm = New OleDbCommand("SELECT * FROM tbl_content WHERE id=1",myConn) 'You need to associate the connection with the command.

     myConn.Open()
     OleDbDataReader dr = myComm.ExecuteReader()

     Dim tablestring As String
     while(dr.Read())
          tablestring = dr("ColumnName")

     'You just need to loop through the rows in the datareader and do whatever you want with the values.
End Sub
0
 

Author Comment

by:Enniobozzetti
ID: 13776996
That worked thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question