954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQL, Dataview, DataTable and DataAdapter.Update

when trying to update a sql database i get the following error message on Update

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

the column UserID is the PrimaryKey

any ideas would be appreciated

Thanks
Peter


example code:

Private dt as new datatable
private dv as new dataview

Public sub GetData
    dim da as new SqlDataAdapter("SELECT * FROM tblUser", sqlconn.connectionstring)
    da.fill(dt)
    dt.TableName = "tblUser

    dv.table = dt
    dgUserData.datasource = dv
end sub

private sub setdata()
    Dim Row As DataRow
    Row = dv.Item(dgUserData.CurrentRow.Index).Row

    Row("username") = txtUsername.text
end sub

private sub SaveDataToServer()
    dim da as new SqlDataAdapter("SELECT * FROM tblUser", sqlconn.connectionstring)

da.update(dt)

end sub
ptaylor965
Junior Poster
170 posts since Oct 2006
Reputation Points: 16
Solved Threads: 19
 

the SQL SELECT Query is now

"SELECT DISTINCT * FROM tblUser"
ptaylor965
Junior Poster
170 posts since Oct 2006
Reputation Points: 16
Solved Threads: 19
 

Is your User Name Unique ?
Check that first .

Try this also for update.

http://vb.net-informations.com/dataadapter/dataadapter-updatecommand-sqlserver.htm

lemo.

chan_lemo
Newbie Poster
17 posts since Oct 2008
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You