Solved

I get the Error : Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Posted on 2009-07-13
8
802 Views
Last Modified: 2012-05-07
Hello, I'm trying to update a DataSet using the DataAdapter Update method. However I get the error "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information." when I try.  In the original SQL database a primary key is set. But somehow the sqlcommandbuilder doesn't recognize it. Is there a way to manually set the pk in the dataset... or pointing the dataset to the original pk...?
I've tried almost everything
System.Data.SqlClient.SqlConnection Data_Connect = new System.Data.SqlClient.SqlConnection(conn_string);

        Data_Connect.Open();

        System.Data.SqlClient.SqlDataAdapter Login_Adapter = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM ongs", Data_Connect);

        Login_Adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        System.Data.SqlClient.SqlCommandBuilder Cmd = new System.Data.SqlClient.SqlCommandBuilder(Login_Adapter);

        //Login_Set.Tables["ongs"].PrimaryKey[0] = Login_Set.Tables["ongs"].Columns[0];
 
 
 

        DataRow New_User = Login_Set.Tables["ongs"].NewRow();

        New_User["Email"] = TextBox3.Text;

        New_User["password"] = TextBox4.Text;

        New_User["Organizacion"] = TextBox6.Text;

        New_User["Org_siglas"] = TextBox7.Text;

        New_User["first_name"] = TextBox8.Text;

        if (DropDownList1.SelectedIndex.ToString().Equals("Masculino"))

            New_User["Sexo"] = "M";

        else if (DropDownList1.SelectedIndex.ToString().Equals("Femenino"))

            New_User["Sexo"] = "F";

        New_User["pais"] = TextBox10.Text;

        New_User["fax"] = TextBox11.Text;

        New_User["phone"] = TextBox12.Text;

        New_User["Direccion"] = TextBox13.Text;

        Login_Set.Tables["ongs"].Rows.Add(New_User);

        //New_User.AcceptChanges();

        //New_User.BeginEdit();

        //New_User.EndEdit();

        Login_Adapter.Update(Login_Set,"ongs");
 

        Data_Connect.Close();

Open in new window

0
Comment
Question by:CharLieYv
  • 4
  • 4
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24849531
There isn't any way to override that behavior, but with SQL Server, the SqlCommandBuilder shouldn't have any problem finding a primary key, if you are getting data from the right table.
0
 

Author Comment

by:CharLieYv
ID: 24849584
For some reason the commandbuilder doesn't recognize the primary key in the column. When I try to manually specify a pk in the dataset as shown below, then it leaves the pk column null and I get an error(pk cant be null). I just want to add a new row to the database.
DataColumn[] keyColumn = new DataColumn[1];

        keyColumn[0] = Login_Set.Tables["ongs"].Columns["key_"];

        Login_Set.Tables["ongs"].PrimaryKey = keyColumn;

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24849623
Can you attach a screen shot from the table designer, so that I can see the primary key?
0
 

Author Comment

by:CharLieYv
ID: 24849713
The table was already created. I'm working on top of it (using it) so I cant create a new table or modify it.
screen.JPG
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 96

Expert Comment

by:Bob Learned
ID: 24849762
No, I meant from the table designer.

Example from AdventureWorks sample table:


Table-Designer----Primary-Key-In.png
0
 

Author Comment

by:CharLieYv
ID: 24849858
Here it is...
screen.JPG
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24849960
If you look at the screen shot that I attached, you will notice a yellow key, indicating the primary key column.  That is missing from the 'key_' column in your screen shot.   That means that you don't have the column marked as a primary key, and would explain the error that you get.
0
 

Author Comment

by:CharLieYv
ID: 24849976
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML to SQL Table using c# 5 47
Visual Studio: built-in keystroke automation 2 26
Data Saving(2) 2 28
Asp.net mvc entity issue 6 20
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now