Query. Can't Execute

Discussion in 'ASP .Net' started by Shapper, Sep 14, 2006.

  1. Shapper

    Shapper Guest

    Hello,

    I have the tables content and content_localized in a Microsoft Access
    database.

    I created a Query in my Microsoft Access database named
    "content_SELECT":

    SELECT content_localized.content_html
    FROM content INNER JOIN content_localized ON content.content_id =
    content_localized.content_id
    WHERE (((content.content_page)=[@Page]) AND
    ((content.content_name)=[@Name]) AND
    ((content_localized.content_culture)=[@Culture]));

    I tested the Query inside Microsoft Access and it worked fine returning
    the expected record.

    On my Asp.Net 2.0 web site I created a function which should execute
    the Query "content_SELECT" and return value on field
    content_localized.content_html.

    I tryied everything, I could think of, to make this work but I had no
    success.

    My function code is as follows:

    ---------------------------------------------------------------------------------
    Public Function Load()

    ' Set Connection
    Dim connectionString As String =
    ConfigurationManager.ConnectionStrings(_ConnectionString).ConnectionString
    Dim connection As New
    System.Data.OleDb.OleDbConnection(connectionString)

    ' Set Command
    Dim command As New System.Data.OleDb.OleDbCommand
    With command
    .CommandText = "EXECUTE content_SELECT"
    .Connection = connection
    .CommandType = CommandType.Text
    End With

    ' Add Parameters
    With command.Parameters
    .Add(New OleDb.OleDbParameter("[@Culture]", "pt-PT"))
    .Add(New OleDb.OleDbParameter("[@Page]", "Default.aspx"))
    .Add(New OleDb.OleDbParameter("[@Name]", "Newsletter"))
    End With

    ' Execute the Command
    connection.Open()
    Dim contentHtml As OleDb.OleDbDataReader = command.ExecuteReader
    If contentHtml.Read Then
    Return contentHtml.Item("content_html").ToString()
    Else
    Return "Something is Wrong" ***
    End If
    contentHtml.Close()
    connection.Close()

    End Function
    ---------------------------------------------------------------------------------

    My page doesn't display any error but the function returns the string
    "Something is Wrong" from my code line ***

    Could someone, please, help me out?

    Thanks,
    Miguel
     
    Shapper, Sep 14, 2006
    #1
    1. Advertising

  2. Shapper

    Hans Kesting Guest

    > Hello,
    >
    > I have the tables content and content_localized in a Microsoft Access
    > database.
    >
    > I created a Query in my Microsoft Access database named
    > "content_SELECT":
    >
    > SELECT content_localized.content_html
    > FROM content INNER JOIN content_localized ON content.content_id =
    > content_localized.content_id
    > WHERE (((content.content_page)=[@Page]) AND
    > ((content.content_name)=[@Name]) AND
    > ((content_localized.content_culture)=[@Culture]));
    >
    > I tested the Query inside Microsoft Access and it worked fine returning
    > the expected record.
    >
    > On my Asp.Net 2.0 web site I created a function which should execute
    > the Query "content_SELECT" and return value on field
    > content_localized.content_html.
    >
    > I tryied everything, I could think of, to make this work but I had no
    > success.
    >
    > My function code is as follows:
    >
    > ---------------------------------------------------------------------------------
    > Public Function Load()
    >
    > ' Set Connection
    > Dim connectionString As String =
    > ConfigurationManager.ConnectionStrings(_ConnectionString).ConnectionString
    > Dim connection As New
    > System.Data.OleDb.OleDbConnection(connectionString)
    >
    > ' Set Command
    > Dim command As New System.Data.OleDb.OleDbCommand
    > With command
    > .CommandText = "EXECUTE content_SELECT"
    > .Connection = connection
    > .CommandType = CommandType.Text
    > End With
    >
    > ' Add Parameters
    > With command.Parameters
    > .Add(New OleDb.OleDbParameter("[@Culture]", "pt-PT"))
    > .Add(New OleDb.OleDbParameter("[@Page]", "Default.aspx"))
    > .Add(New OleDb.OleDbParameter("[@Name]", "Newsletter"))
    > End With
    >
    > ' Execute the Command
    > connection.Open()
    > Dim contentHtml As OleDb.OleDbDataReader = command.ExecuteReader
    > If contentHtml.Read Then
    > Return contentHtml.Item("content_html").ToString()
    > Else
    > Return "Something is Wrong" ***
    > End If
    > contentHtml.Close()
    > connection.Close()
    >
    > End Function
    > ---------------------------------------------------------------------------------
    >
    > My page doesn't display any error but the function returns the string
    > "Something is Wrong" from my code line ***
    >
    > Could someone, please, help me out?
    >
    > Thanks,
    > Miguel


    Try leaving out the [], as in:
    .Add(New OleDb.OleDbParameter("@Name", "Newsletter"))

    (reason: the name of the parameter is "@Name", not "[@Name]")

    Not that there are some syntax differences between Access used directly
    or via OleDb*. One difference I know is wildcards: Access supports "*"
    and "?", OleDb needs to have "%" and "_".

    Hans Kesting
     
    Hans Kesting, Sep 14, 2006
    #2
    1. Advertising

  3. Shapper

    shapper Guest

    Hans Kesting wrote:
    > > Hello,
    > >
    > > I have the tables content and content_localized in a Microsoft Access
    > > database.
    > >
    > > I created a Query in my Microsoft Access database named
    > > "content_SELECT":
    > >
    > > SELECT content_localized.content_html
    > > FROM content INNER JOIN content_localized ON content.content_id =
    > > content_localized.content_id
    > > WHERE (((content.content_page)=[@Page]) AND
    > > ((content.content_name)=[@Name]) AND
    > > ((content_localized.content_culture)=[@Culture]));
    > >
    > > I tested the Query inside Microsoft Access and it worked fine returning
    > > the expected record.
    > >
    > > On my Asp.Net 2.0 web site I created a function which should execute
    > > the Query "content_SELECT" and return value on field
    > > content_localized.content_html.
    > >
    > > I tryied everything, I could think of, to make this work but I had no
    > > success.
    > >
    > > My function code is as follows:
    > >
    > > ---------------------------------------------------------------------------------
    > > Public Function Load()
    > >
    > > ' Set Connection
    > > Dim connectionString As String =
    > > ConfigurationManager.ConnectionStrings(_ConnectionString).ConnectionString
    > > Dim connection As New
    > > System.Data.OleDb.OleDbConnection(connectionString)
    > >
    > > ' Set Command
    > > Dim command As New System.Data.OleDb.OleDbCommand
    > > With command
    > > .CommandText = "EXECUTE content_SELECT"
    > > .Connection = connection
    > > .CommandType = CommandType.Text
    > > End With
    > >
    > > ' Add Parameters
    > > With command.Parameters
    > > .Add(New OleDb.OleDbParameter("[@Culture]", "pt-PT"))
    > > .Add(New OleDb.OleDbParameter("[@Page]", "Default.aspx"))
    > > .Add(New OleDb.OleDbParameter("[@Name]", "Newsletter"))
    > > End With
    > >
    > > ' Execute the Command
    > > connection.Open()
    > > Dim contentHtml As OleDb.OleDbDataReader = command.ExecuteReader
    > > If contentHtml.Read Then
    > > Return contentHtml.Item("content_html").ToString()
    > > Else
    > > Return "Something is Wrong" ***
    > > End If
    > > contentHtml.Close()
    > > connection.Close()
    > >
    > > End Function
    > > ---------------------------------------------------------------------------------
    > >
    > > My page doesn't display any error but the function returns the string
    > > "Something is Wrong" from my code line ***
    > >
    > > Could someone, please, help me out?
    > >
    > > Thanks,
    > > Miguel

    >
    > Try leaving out the [], as in:
    > .Add(New OleDb.OleDbParameter("@Name", "Newsletter"))
    >
    > (reason: the name of the parameter is "@Name", not "[@Name]")
    >
    > Not that there are some syntax differences between Access used directly
    > or via OleDb*. One difference I know is wildcards: Access supports "*"
    > and "?", OleDb needs to have "%" and "_".
    >
    > Hans Kesting


    Hello,

    I removed the [] and I still have the same problem.
    What else should I try?
    I have been searching in Google for a solution and I really can't find
    the reason why my code is not working.

    Thanks,
    Miguel
     
    shapper, Sep 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beryl Small
    Replies:
    1
    Views:
    670
    bruce barker
    Dec 2, 2003
  2. Marcelo Moreira
    Replies:
    2
    Views:
    385
    DannyB
    Jul 17, 2008
  3. Baby Lion
    Replies:
    3
    Views:
    596
    Baby Lion
    Oct 1, 2006
  4. jonny
    Replies:
    2
    Views:
    664
    Masudur
    Jul 30, 2007
  5. Savas Ates
    Replies:
    1
    Views:
    287
    Patrice
    Aug 17, 2004
Loading...

Share This Page