Results 1 to 3 of 3

Thread: bug in connection to access

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    3

    bug in connection to access

    hi
    this is my web:
    web
    and this is my cod:
    Imports System.Data
    Imports System.Data.OleDb
    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.ComponentModelB
    Imports System.Data.SqlClient
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls
    Public Class index
    Inherits System.Web.UI.Page
    #Region " Web Form Designer Generated Code "
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    End Sub
    Protected MyConnection As System.Data.OleDb.OleDbConnection
    Protected UpdateCommand As System.Data.OleDb.OleDbDataAdapter
    Public connectionOpen As Boolean
    Public location As String
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected arrHL As WebControls.HyperLink()
    Protected WithEvents LblError As System.Web.UI.WebControls.Label
    Private designerPlaceholderDeclaration As System.Object
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    InitializeComponent()
    End Sub
    #End Region
    Protected arrayImages As WebControls.Image()
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    fill()
    Me.HyperLink1.Text = Me.getText("c")
    End Sub
    Sub setConnection()
    MyConnection = New System.Data.OleDb.OleDbConnection( _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
    Me.location)
    End Sub
    Sub fill()
    Try
    Me.location = "a.mdb"
    setConnection()
    Me.closeConnection()
    Catch ex As Exception
    Me.LblError.Text = ex.ToString
    End Try
    End Sub
    Function getText(ByVal name As String)
    Try
    Dim result As String
    Dim out As OleDbDataReader
    Me.openConnection()
    Dim cmd As New System.Data.OleDb.OleDbCommand
    cmd.Connection = MyConnection
    cmd.CommandText = "select text from b where @name=name"
    cmd.Parameters.Add("@name", SqlDbType.VarChar)
    cmd.Parameters("@name").Value = name
    Dim r As OleDbDataReader
    r = cmd.ExecuteReader
    While r.Read
    result = (r("text"))
    End While
    closeConnection()
    r.Close()
    Return result
    Catch ex As Exception
    Me.LblError.Text = ex.ToString
    End Try
    End Function
    Sub openConnection()
    If Not Me.connectionOpen Then
    Me.MyConnection.Open()
    connectionOpen = True
    End If
    End Sub
    Sub closeConnection()
    If Me.connectionOpen Then
    Me.MyConnection.Close()
    connectionOpen = False
    End If
    End Sub
    End Class

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: bug in connection to access

    The path to your MDB file seems to be incorrect. Try giving it a relative path

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: bug in connection to access

    Also I don't see the name of the db.... just me.location..... which, I think would be the location of the page....

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width