Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't delete row
Message
From
10/04/2007 13:13:52
 
 
To
10/04/2007 12:56:45
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01214017
Message ID:
01214021
Views:
14
The CommandBuilder is not creating the commands. The DeleteCommand = null. I have specified the primary key and am retrieving it in the Select statement.

So, the next question is, why isn't the CommandBuilder working?

>I'm trying to delete a row in a datatable. I've followed examples from three different places, but I still get the error "Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information."
>
>Here's the scaled down code:
>
>SqlConnection conn;
>SqlDataAdapter daAllData;
>DataSet dsAllData;
>DataRelation relGroupsFeeds;
>
>conn = new SqlConnection(@"Server=(local); Integrated Security = true; Database = FeedMe");
>daAllData = new SqlDataAdapter("SELECT GroupPK, Description FROM Groups", conn);
>
>SqlCommandBuilder commandBuilder = new SqlCommandBuilder(daAllData);
>
>dsAllData = new DataSet();
>daAllData.Fill(dsAllData, "Groups");
>
>// I can leave these three lines in or out. I get the same result.
>DataColumn[] keys = new DataColumn[1];
>keys[0] = dsAllData.Tables["Groups"].Columns["GroupPK"];
>dsAllData.Tables["Groups"].PrimaryKey = keys;
>
>string ID = "4";
>int groupPK = int.Parse(ID);
>DataRow row = dsAllData.Tables["Groups"].Rows.Find(groupPK);
>row.Delete();
>
>// Error occurs on Update()
>daAllData.Update(dsAllData, "Groups");
>conn.Close();
>
>Any suggestions for what to look at?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform