 |
BOOK: Beginning ASP.NET 1.0  | This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

December 24th, 2003, 02:57 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter-13-direct SQL command-ExecuteNonQuery erro
Direct SQL commands is showing an error at line 30 showing this in the browser
**************************************
Server Error in '/' Application.
--------------------------------------------------------------------------------
No value given for one or more required parameters.
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: No value given for one or more required parameters.
Source Error:
Line 28:
Line 29:
Line 30: objCmd.ExecuteNonQuery();
Line 31:
Line 32:
Source File: C:\Documents and Settings\Jenu\Desktop\testing\directsql.aspx Line: 30
Stack Trace:
[OleDbException (0x80040e10): No value given for one or more required parameters.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) +122
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.ExecuteNonQuery() +67
ASP.directsql_aspx.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Jenu\Desktop\testing\directsql.aspx:30
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731
***************************************
The ASPX Source i used is the -Direct SQL command try it out with just the modified daabase path
----------------
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
OleDbConnection objConnection = null;
OleDbCommand objCmd = null;
string strConnection, strSQL;
strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=C:\Documents and Settings\Jenu\Desktop\testing\northwind.mdb";
// Create and open the connection object
objConnection = new OleDbConnection(strConnection);
objConnection.Open();
// Set the SQL string
strSQL = "INSERT INTO Employees (FirstName,LastName) VALUES ( `Beth` , `Hart` )";
// Create the Command and set its properties
objCmd = new OleDbCommand(strSQL, objConnection);
// Execute the command
objCmd.ExecuteNonQuery();
lblStatus.Text = " Command run ";
}
</script>
<html>
<head>
</head>
<body>
<h2>Using SQL directly
</h2>
<asp:Label id="lblStatus" runat="server"></asp:Label>
</body>
</html>
----------------
|
|

December 24th, 2003, 03:03 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
by the way,
the source code is from the book C# FOR BEGINERS pages 527-528
|
|

December 29th, 2003, 08:37 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok..guys i got it.... and u would like to know how invisible that error is....
see the quotes in the insert statement with the values `Beth` , `Hart`
these are the culprits when u try to copy and paste the code...
compare the difference between (`Beth` , `Hart`) and ('Beth', 'Hart')
eys can hardly catch the difference between ` and '
:)
so be careful
nothing wrong with the code
|
|

May 13th, 2004, 10:42 PM
|
|
Registered User
|
|
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I fixed the problem by changing this line:
strSQL = "INSERT INTO 'Employees' ( 'FirstName' , 'LastName' ) VALUES ( 'Beth' , 'Hart' )";
With this line (remember to replace ` with ')
strSQL = "INSERT INTO Employees (FirstName,LastName) VALUES ('Beth','Hart')";
I hope this helps someone.
|
|
 |