Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / January 2008



Tip: Looking for answers? Try searching our database.

Problem with queries... Call for help.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
johnmay1248 - 18 Jan 2008 17:48 GMT
I am having a problem with queries running in this code  When I use the
query "SELECT * FROM sample" the code runs and the data grid binds and shows
the contents of the sample table. If I change the query to filter the
results such as "SELECT * FROM sample WHERE (sales > 2000)" the code fails
on - objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection) with an unknown
error.

If I load the database up into access2000 and run the sql queries they run
as expected so I know they are valid queries of the data

I am a noob at asp.net data. Can anybody give me a hand?

The Code I am using is below followed by the error info with the stack
trace.

-----------------------------------------------------------------------------

Imports System.Data.OleDb
Imports System.Data

   Sub btnRunQuery_OnClick(ByVal Sender As Object, ByVal E As EventArgs)
       Dim objConnection As OleDbConnection
       Dim objCommand As OleDbCommand
       Dim objDataReader As OleDbDataReader
       Dim strSQLQuery As String

       objConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("NewDatabase.mdb") & ";")

       strSQLQuery = "SELECT * FROM sample"

       'strSQLQuery = "SELECT * FROM sample WHERE (sales > 2000)"

       'strSQLQuery = "SELECT * FROM sample WHERE key_id=5"

       'strSQLQuery = "SELECT * FROM sample WHERE last_name='Johnson'"

       objCommand = New OleDbCommand(strSQLQuery, objConnection)

       objConnection.Open()

       objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)

       lblSQLCommandLabel.Text = strSQLQuery

       EmployeeDataGrid.DataSource = objDataReader
       EmployeeDataGrid.DataBind()
   End Sub

-------------------------------------------------------------

Unknown
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Unknown

Source Error:
Line 61:         objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)

Stack Trace:

[OleDbException (0x80040e14): Unknown]
  System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
  System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
  System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
  System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult)
  System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
  System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
  Database101.WebForm1.btnRunQuery_OnClick(Object Sender, EventArgs E) in
c:\Database101\WebForm1.aspx.vb:61
  System.Web.UI.WebControls.Button.OnClick(EventArgs e)
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  System.Web.UI.Page.ProcessRequestMain()

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.6060; ASP.NET
Version:1.0.3705.6060
Bob Barrows [MVP] - 18 Jan 2008 18:05 GMT
> I am having a problem with queries running in this code  When I use
> the
[quoted text clipped - 4 lines]
> fails
> on - objDataReader =

There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice),  but this is a classic asp newsgroup. ASP.Net is
a different technology from classic ASP. While you may be lucky enough
to find a dotnet-savvy person  here who can answer your question, you
can eliminate the luck factor by posting your question to a newsgroup
where the dotnet-savvy people hang out.  I suggest
microsoft.public.dotnet.framework.aspnet.
There are also forums at www.asp.net where you can find a lot of people
to help you.

Signature

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.