By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

Query. Can't Execute

P: n/a
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(_Connection String).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

Sep 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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(_Connection String).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
Sep 14 '06 #2

P: n/a

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(_Connection String).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

Sep 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.