PDA

View Full Version : commandtext error


villagecirc
11-20-2003, 09:52 AM
Server Error in '/Test' Application.
--------------------------------------------------------------------------------

Expected query name after EXECUTE.
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: Expected query name after EXECUTE.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[OleDbException (0x80040e14): Expected query name after EXECUTE.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior) +69
System.Data.OleDb.OleDbCommand.System.Data.IDbComm and.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
Test.Test.ReturnDataset(String cmdText) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.ne t\test\test.aspx.cs:50
Test.Test.Button1_Click(Object sender, EventArgs e) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.ne t\test\test.aspx.cs:82
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.903


heres the code ....

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Web.Configuration;

namespace Test
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{

// // Put user code to initialize the page here
// DataSet MYDS = ReturnDataset("SELECT * FROM Events");



}

public static DataSet ReturnDataset(string cmdText)
{
OleDbConnection conn = new OleDbConnection ();
{
conn.ConnectionString = System.Configuration.ConfigurationSettings.AppSett ings["ConnectionString"];
conn.Open();

OleDbDataAdapter da = new OleDbDataAdapter ();
OleDbCommand commSQL;
commSQL = new OleDbCommand();
commSQL.Connection = conn;
commSQL.CommandType= CommandType.StoredProcedure;
commSQL.CommandText= cmdText;
da.SelectCommand = commSQL ;

DataSet ds = new DataSet();
da.Fill (ds) ;

conn.Close() ;
return ds;
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string ct ="SELECT * FROM Events";
DataSet MYDS = ReturnDataset(ct);
}
}
}


if I comment out the button1click statements it runs in the browser fine I think the error is in my ct statement do I need to designate a password or something in my command text statement..I did double check that Events table it exists and is spelled correctly....At a glance does anyone see anything out of place I have been banging my head against my wall trying to get this to work....The first time doings something is always a pain....[V]

here is the connection string it seems to be working as I only get an error when I try to call the ReturnDataset function. If I pass it a different named table I get a different error saying table does not exist so I am assumeing it is finding the table and the problem is the command text statement....


The web.config file is running within the browser I think it is good..
<configuration>
<appSettings>
<!-- add this kind of key -->
<add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\web\villagecirc\htdocs\_database\BT.mdb" />
</appSettings>
<system.web>

Matthew H. Paulson
matt@villagecircle.net
http://www.villagecircle.net

steurm
11-20-2003, 11:16 AM
Matthew,

You should not set the CommandType to StoredProcedure but to Text.
If you want to use the StoredProcedure, the CommandText should be the name of a query in your access database.
[b]quote:
...
<s>commSQL.CommandType= CommandType.StoredProcedure;commSQL.CommandType= CommandType.Text;
...
</blockquote id="quote"></font id="quote">

Success

--
Steurm
www.steurm.net/steurm

villagecirc
11-21-2003, 11:24 AM
I was finally able to get the dataset bound to a datagrid and I wanted to thank everyone for takeing the time to respond to my error messages. The first time doing something is always like pulling teeth to me but preseverence is the key...

I had one more question are we able to update the data base using update commands delete commands and insert commands and so on?????

Matthew H. Paulson
matt@villagecircle.net
http://www.villagecircle.net



Matthew H. Paulson
matt@villagecircle.net
http://www.villagecircle.net

KPayne
11-27-2003, 12:49 PM
Matthew,

If you use a DataAdapter to access the database, the Updates, Inserts and Deletes all happen behind the scenes when you call DataAdapter.Update(). You can use an OleDbCommandBuilder to have .NET create the Update, Insert and Delete commands automatically, or you can create each command manually in the same way that you create the Select command.

Keith Payne
Technical Marketing Solutions