I have two relational tables: the Profiles table which contains 3 kinds of user roles (Manager, Developer, Common User) and the Users table which contains information about the user and their roles ID (Profile_ID field) in the Access 2010 database.
I created a Webform in ASP.NET which should simply register users, asking for their names, selecting their roles in a dropdown list and inserting it all in the Access database. As in the following code:
Dim cs As String = ConfigurationManager.ConnectionStrings("Access 2010").ConnectionString
Dim cn As New OleDbConnection(cs)
Dim cmd As New OleDbCommand
With cmd
.CommandText = "INSERT INTO Users (nome, Profile_ID) VALUES ('" & Me.txtNome.Text & "', " & Me.ddRoles.SelectedIndex & ")"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()
It happens that I can't insert in the database because they have a relationship between each other, it gives me an error. Actually, I just need to insert data in the Users table 'cause the roles are fixed. How can I do it?
EDIT
The error I get is You can not add or change records, it is necessary that they have a related record in table 'Profiles'.