Query. Can't Execute

S

Shapper

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
 
H

Hans Kesting

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
 
S

shapper

Hans said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top