UpdateCommand error

J

Jim in Arizona

I'm doing my best to learn ASPNET from a book devoted to ASPNET 1.0. So far,
I haven't run into any problems, until now.

This is a simple page that should just show the sql strings created by the
CommandBuilder (or is it data adapter) object.

Here is my code (the books code, actually):

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim strConnection, strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objBuilder As OleDbCommandBuilder
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\hhsinternal\comlog\testing.mdb"
strSQL = "SELECT FirstName, LastName from tmaster;"


objConnection = New OleDbConnection(strConnection)
objAdapter = New OleDbDataAdapter(strSQL, objConnection)
objBuilder = New OleDbCommandBuilder(objAdapter)

objAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objAdapter.InsertCommand = objBuilder.GetInsertCommand()
objAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
lblselectcmd.Text = objAdapter.SelectCommand.CommandText
lblupdatecmd.Text = objAdapter.UpdateCommand.CommandText
lblinsertcmd.Text = objAdapter.InsertCommand.CommandText
lbldeletecmd.Text = objAdapter.DeleteCommand.CommandText

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title></head><body>
<form id="form1" runat="server">
<div>
<table border=1>
<tr>
<th>Command</th>
<th>CommandText</th>
</tr>
<tr>
<td>Select Command</td>
<td><asp:Label id="lblselectcmd" runat=server /></td>
</tr>
<tr>
<td>Update Command</td>
<td><asp:Label id="lblupdatecmd" runat=server /></td>
</tr>
<tr>
<td>Insert Command</td>
<td><asp:Label id="lblinsertcmd" runat=server /></td>
</tr>
<tr>
<td>Delete Command</td>
<td><asp:Label id="lbldeletecmd" runat=server /></td>
</tr>
</table>
</div>
</form>
</body>
</html>

I don't really know what this error means or what I should do about it.

Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information.
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.InvalidOperationException: Dynamic SQL generation
for the UpdateCommand is not supported against a SelectCommand that does not
return any key column information.

Source Error:


The source code that generated this unhandled exception can only be
shown when compiled in debug mode. To enable this, please follow one of the
below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated
the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your
application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given
application to be compiled in debug mode. The first technique will cause
only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a
memory/performance overhead. You should make sure that an application has
debugging disabled before deploying into production scenario.


Stack Trace:


[InvalidOperationException: Dynamic SQL generation for the UpdateCommand is
not supported against a SelectCommand that does not return any key column
information.]
System.Data.Common.CommandBuilder.BuildUpdateCommand(DataTableMapping
mappings, DataRow dataRow) +3049
System.Data.OleDb.OleDbCommandBuilder.GetUpdateCommand() +35
ASP.datasets3_aspx.Page_Load(Object sender, EventArgs e) +111
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
 
J

Jim in Arizona

Sorry, forgot to add debug=true so I could get the real error.
So, here's my code, again, and the error is below that.
Thanks.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim strConnection, strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objBuilder As OleDbCommandBuilder
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\hhsinternal\comlog\testing.mdb"
strSQL = "SELECT FirstName, LastName from tmaster;"


objConnection = New OleDbConnection(strConnection)
objAdapter = New OleDbDataAdapter(strSQL, objConnection)
objBuilder = New OleDbCommandBuilder(objAdapter)

objAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objAdapter.InsertCommand = objBuilder.GetInsertCommand()
objAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
lblselectcmd.Text = objAdapter.SelectCommand.CommandText
lblupdatecmd.Text = objAdapter.UpdateCommand.CommandText
lblinsertcmd.Text = objAdapter.InsertCommand.CommandText
lbldeletecmd.Text = objAdapter.DeleteCommand.CommandText

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title></head><body>
<form id="form1" runat="server">
<div>
<table border=1>
<tr>
<th>Command</th>
<th>CommandText</th>
</tr>
<tr>
<td>Select Command</td>
<td><asp:Label id="lblselectcmd" runat=server /></td>
</tr>
<tr>
<td>Update Command</td>
<td><asp:Label id="lblupdatecmd" runat=server /></td>
</tr>
<tr>
<td>Insert Command</td>
<td><asp:Label id="lblinsertcmd" runat=server /></td>
</tr>
<tr>
<td>Delete Command</td>
<td><asp:Label id="lbldeletecmd" runat=server /></td>
</tr>
</table>
</div>
</form>
</body>
</html>



Server Error in '/' Application.
--------------------------------------------------------------------------------

Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information.
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.InvalidOperationException: Dynamic SQL generation
for the UpdateCommand is not supported against a SelectCommand that does not
return any key column information.

Source Error:

Line 23:
Line 24: objBuilder = New OleDbCommandBuilder(objAdapter)
Line 25: objAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
Line 26: objAdapter.InsertCommand = objBuilder.GetInsertCommand()
Line 27: objAdapter.DeleteCommand = objBuilder.GetDeleteCommand()

Source File: E:\hhsinternal\comlog\datasets3.aspx Line: 25

Stack Trace:

[InvalidOperationException: Dynamic SQL generation for the UpdateCommand is
not supported against a SelectCommand that does not return any key column
information.]
System.Data.Common.CommandBuilder.BuildUpdateCommand(DataTableMapping
mappings, DataRow dataRow) +3049
System.Data.OleDb.OleDbCommandBuilder.GetUpdateCommand() +35
ASP.datasets3_aspx.Page_Load(Object sender, EventArgs e) in
E:\hhsinternal\comlog\datasets3.aspx:25
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
 
M

Marina

Looks like your table does not have a primary key defined.

Jim in Arizona said:
I'm doing my best to learn ASPNET from a book devoted to ASPNET 1.0. So
far, I haven't run into any problems, until now.

This is a simple page that should just show the sql strings created by the
CommandBuilder (or is it data adapter) object.

Here is my code (the books code, actually):

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim strConnection, strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objBuilder As OleDbCommandBuilder
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\hhsinternal\comlog\testing.mdb"
strSQL = "SELECT FirstName, LastName from tmaster;"


objConnection = New OleDbConnection(strConnection)
objAdapter = New OleDbDataAdapter(strSQL, objConnection)
objBuilder = New OleDbCommandBuilder(objAdapter)

objAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objAdapter.InsertCommand = objBuilder.GetInsertCommand()
objAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
lblselectcmd.Text = objAdapter.SelectCommand.CommandText
lblupdatecmd.Text = objAdapter.UpdateCommand.CommandText
lblinsertcmd.Text = objAdapter.InsertCommand.CommandText
lbldeletecmd.Text = objAdapter.DeleteCommand.CommandText

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title></head><body>
<form id="form1" runat="server">
<div>
<table border=1>
<tr>
<th>Command</th>
<th>CommandText</th>
</tr>
<tr>
<td>Select Command</td>
<td><asp:Label id="lblselectcmd" runat=server /></td>
</tr>
<tr>
<td>Update Command</td>
<td><asp:Label id="lblupdatecmd" runat=server /></td>
</tr>
<tr>
<td>Insert Command</td>
<td><asp:Label id="lblinsertcmd" runat=server /></td>
</tr>
<tr>
<td>Delete Command</td>
<td><asp:Label id="lbldeletecmd" runat=server /></td>
</tr>
</table>
</div>
</form>
</body>
</html>

I don't really know what this error means or what I should do about it.

Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information.
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.InvalidOperationException: Dynamic SQL
generation for the UpdateCommand is not supported against a SelectCommand
that does not return any key column information.

Source Error:


The source code that generated this unhandled exception can only be
shown when compiled in debug mode. To enable this, please follow one of
the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated
the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your
application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given
application to be compiled in debug mode. The first technique will cause
only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a
memory/performance overhead. You should make sure that an application has
debugging disabled before deploying into production scenario.


Stack Trace:


[InvalidOperationException: Dynamic SQL generation for the UpdateCommand
is not supported against a SelectCommand that does not return any key
column information.]
System.Data.Common.CommandBuilder.BuildUpdateCommand(DataTableMapping
mappings, DataRow dataRow) +3049
System.Data.OleDb.OleDbCommandBuilder.GetUpdateCommand() +35
ASP.datasets3_aspx.Page_Load(Object sender, EventArgs e) +111
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
 
J

Jim in Arizona

Marina said:
Looks like your table does not have a primary key defined.

I can't believe it.
My tables (the only two in that DB) each have a PK, but I didn't select the
PK field in my sql statement:
SELECT firstname, lastname from tmaster

So, I changed it to
SELECT * from tmaster

and now it works.

I didn't think it matterd what I had in my select statement as long as I
wasn't later trying to display or use data that didn't exist in the select
statement.

Thanks,
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top