0

Hi,

I've been working on getting a GUI connected to a database so I can input data into the database. However when getting to the 'making a save button' I get this problem on line 14:

            Private da As New SqlDataAdapter("Select Name, Number, Email From Contacts", cs)
            Private ds As New DataSet
            Private cmb As New SqlCommandBuilder(da)
            Private Sub Main2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

                da.Fill(ds, "Contacts")

                dg.DataSource = ds.Tables("Contacts")

            End Sub

            Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

                da.UpdateCommand = cmb.GetUpdateCommand
                da.Update(ds.Tables("Contacts"))

            End Sub

The line of code that says da.UpdateCommand = cmb.GetUpdateCommand produces an error that says:

InvalidOperationException was unhandled
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

I'm not 100% sure what that means but I have tried looking but nothing I've found applies to the Dynamic SQL.

Any help would be appreciated!

Thank you!

Edited by az_ez

3
Contributors
3
Replies
6
Views
4 Years
Discussion Span
Last Post by az_ez
0

Your Select command does not bring back any primary key / identifer so the update does not know what record to update...

0

I'm not that familiar with using data adapters, etc (I tend to go with basic ADO) but what reason do you have to assume that Name is not a primary key?

0

Your Select command does not bring back any primary key / identifer so the update does not know what record to update...

I would have assumed that you could define that witha where clause like when you're actually querying?

what reason do you have to assume that Name is not a primary key?

I assumed it would be a primary key since no name would be the same? I guess I was wrong and I'll look into assigning a primary key properly.

Thank you for getting back to me!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.