472,353 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Dynamic SQL generation for the UpdateCommand is not supported ...

The full error message is "Dynamic SQL generation for the UpdateCommand is
not supported against a SelectCommand that does not return any key column
information."

I am getting this error when updating a table bound to a datagridview (using
the OLEDataAdapter) when the table does not have a primary key; my code works
when the table does have primary key(s).

Is there a workaround for working with tables that do not have any primary
key(s)?

Thanks for your help.
Jun 12 '07 #1
5 19904
On Jun 12, 9:09 am, AA2e72E <AA2e...@discussions.microsoft.comwrote:
The full error message is "Dynamic SQL generation for the UpdateCommand is
not supported against a SelectCommand that does not return any key column
information."

I am getting this error when updating a table bound to a datagridview (using
the OLEDataAdapter) when the table does not have a primary key; my code works
when the table does have primary key(s).

Is there a workaround for working with tables that do not have any primary
key(s)?
Any reason you can't manually specify the appropriate update command
yourself?

Jon

Jun 12 '07 #2
Thanks Jon; I did not know that I could and now that you have hinted that it
is possible, I do not know how/where.

Here's my code:

public partial class Form1 : Form
{
static string DBTable = "TABLE1";
OleDbDataAdapter da = new OleDbDataAdapter(("SELECT * FROM " +
DBTable), "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\db2.MDB");
DataSet ds = new DataSet();
OleDbCommandBuilder builder = new OleDbCommandBuilder();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
da.Fill(ds, DBTable);
dataGridView1.DataSource = ds.Tables[DBTable].DefaultView;
}

private void button1_Click(object sender, EventArgs e)
{
OleDbCommandBuilder builder = new OleDbCommandBuilder(da);
da.UpdateCommand = builder.GetUpdateCommand();

da.Update(ds.Tables[0].Select(null,null,DataViewRowState.CurrentRows));
}
}

The culprint line is

da.UpdateCommand = builder.GetUpdateCommand();

If my table has a primary key, it works fine and fails it it doesn't.

I 'd appreciate some clues. Thanks.
Jun 12 '07 #3
On Jun 12, 10:36 am, AA2e72E <AA2e...@discussions.microsoft.com>
wrote:
Thanks Jon; I did not know that I could and now that you have hinted that it
is possible, I do not know how/where.
<snip>
The culprint line is

da.UpdateCommand = builder.GetUpdateCommand();

If my table has a primary key, it works fine and fails it it doesn't.

I 'd appreciate some clues. Thanks.
So instead of running that line, run:

da.UpdateCommand = "UPDATE BLAH BLAH";

except using the appropriate SQL.

Jon

Jun 12 '07 #4
Thanks Jon.

Since the table does not have any keys, I can't see how I can use UPDATE; I
can see how I might do it i.e

DELETE FROM TABLE1 // drop all the records

then loop to

INSERT INTO TABLE1 (field list) Values(values)

every row in the datagrid view.

There must be a simpler way, surely!
Jun 12 '07 #5
On Jun 12, 10:58 am, AA2e72E <AA2e...@discussions.microsoft.com>
wrote:
Since the table does not have any keys, I can't see how I can use UPDATE
Well, that entirely depends on exactly what you want to do. If you
really haven't got any way of identifying the row that you want to
update, then indeed you can't do the update, and you've got bigger
problems than ADO.NET at that point - your table is badly designed.

If, however, there *is* some way of identifying the row, but it hasn't
been set as a primary key (for whatever reason) then you can just use
that.

Jon

Jun 12 '07 #6

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

Similar topics

1
by: mr_burns | last post by:
Hi there, How would I check if image generation is supported on my server? I used phpinfo() but didnt know what to look for. Also, I just want...
4
by: Martin Mrazek | last post by:
Hi, I have a HTML form and need to generate the action-string (what to do after submission) from values of textfields in the form. It means...
0
by: Hugo Ferreira | last post by:
Hi all, I'm having a problem here, to which I hope someone to be able to help me :) I need to apply a XSLT transformation to the output of all...
5
by: Markus Broy | last post by:
Hello everybody, I have a problem concerning the dynamic creation of a CustomValidator. If I create a CustomControl as shown in the code below...
4
by: abroc | last post by:
sir, i due course of my project i have come up with the need of dynamically generating my crystal report as the input to the report is the...
1
by: Thomas Qvist | last post by:
We are building a suite of programs consisting of both winforms applications and office addins. We would like to pre-generate the...
3
by: fedya | last post by:
I am trying to have the last 12 months to always be the option in the dropdown for a combo box. (Basically a combobox, with dynamic options) I am...
3
by: Jawad Rehman | last post by:
Hello everybody..... I have an excel file which is resided on server,there is some data on the cells .Now i want to generate dynamic graph on...
3
by: Jawad Rehman | last post by:
Hello everybody..... I have an excel file which is resided on server,there is some data on the cells .Now i want to generate dynamic graph on...
4
Samishii23
by: Samishii23 | last post by:
By generator I mean, like MakeForm('Form1'); pushes out a user password form. Then MakeForm('Form2'); make form that adds Car data information into a...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.