473,378 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problem with queries. Call for help.

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.CloseConn ection) 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.CloseConn ection)

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.CloseConn ection)
Stack Trace:

[OleDbException (0x80040e14): Unknown]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior 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.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.6060; ASP.NET
Version:1.0.3705.6060
Jan 18 '08 #1
2 1516
What is the data type (int, decimal , string, text) of "sales" ?

"johnmay1248" <jo*********@bellsouth.netwrote in message
news:z8*******************@bignews5.bellsouth.net. ..
>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.CloseConn ection) 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.CloseConn ection)

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.CloseConn ection)
Stack Trace:

[OleDbException (0x80040e14): Unknown]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)

System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior 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.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.6060;
ASP.NET
Version:1.0.3705.6060


Jan 18 '08 #2
Try using a parameterized query instead of inline SQL statement. Its best
practices technique anyway.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"johnmay1248" wrote:
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.CloseConn ection) 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.CloseConn ection)

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.CloseConn ection)
Stack Trace:

[OleDbException (0x80040e14): Unknown]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior 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.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.6060; ASP.NET
Version:1.0.3705.6060
Jan 19 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: justme | last post by:
Dears I have created the following page to display my data <head> <style type="text/css"> body, td, th, h1, h2 {font-family: sans-serif;} body, td, th {font-size: 100%;} a:link {...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
10
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous...
3
by: coder | last post by:
I am new to programming in PHP however, this should be a pretty straight forward answer. I have three queries that I am pulling for a content form page. 1) The Author List 2) The Content Page...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
12
by: JHNielson | last post by:
I have a simple question, but I can't seem to find the answer. I have this code to count the number of records that pass through a set of processes: It counts how many records go through...
1
by: eblackmo | last post by:
I have a test network consisting of four servers running windows 2003 server R2 SP2. I have set up a domain which functioned correctly for about a day and a half until the other servers decided they...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.