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!

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

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?

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.