I have an Access database with columns titled Key and Username and I'm trying to set some data back to the Username column of the first row of the database. But I get an error:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
The code:
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Dim connection_string As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.UserAppDataPath & "\DDL.mdb"
Dim strSql As String = "SELECT Key,Username FROM table1"
Dim dtb As New DataTable
Dim command As New OleDbCommand
'Dim dataset As DataSet
Using cnn As New OleDbConnection(connection_string)
cnn.Open()
Using dad As New OleDbDataAdapter(strSql, cnn)
dad.Fill(dtb)
'/// send data from datatable to database
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(dad)
command.Connection = cnn
command.CommandText = "update * from table1"
'set data
dtb.Rows(0)("Username") = "PG"
dad.Update(dtb)
End Using
End Using
End Sub
End Class
EDIT: P.S: I did some edits to the code, still gets that error
OleDbDataAdapterI guess .. it makes that entire code incorrect I guess. :/ and theconnectionis also wrong. :/