我有两个关系表:包含三类用户角色的简介表(管理者、开发者、共同用户)和用户表,其中载有2010年访问数据库中用户及其作用信息。
我在伙伴关系中创建了一个网站。 互联网应当简单地登记用户,要求用户姓名,选择用户在减少名单中的作用,并在查阅数据库中插入所有内容。 该代码载有每个登记用户的网格观测和dropdown list,各页载上:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Start connection
Dim cs As String = ConfigurationManager.ConnectionStrings("Access 2010").ConnectionString
Dim cn As New OleDbConnection(cs)
cn.Open()
Retrieve User Data
Dim cmd As New OleDbCommand
With cmd
.Connection = cn
.CommandText = "SELECT * FROM Users"
.CommandType = CommandType.Text
End With
Dim ddlValues As OleDbDataReader = cmd.ExecuteReader()
Populate User Grid View
grdUsers.DataSource = ddlValues
grdUsers.DataBind()
ddlValues.Close()
Retrieve Profile data
With cmd
.Connection = cn
.CommandText = "SELECT * FROM Profiles"
.CommandType = CommandType.Text
End With
ddlValues = cmd.ExecuteReader()
Populate Dropdown Profiles
ddRoles.DataSource = ddlValues
ddRoles.DataTextField = "Nome"
ddRoles.DataValueField = "ID"
ddRoles.DataBind()
Close connections
ddlValues.Close()
cmd.Dispose()
cn.Dispose()
End Sub
Lately it inserts into the database once button clicked:
Protected Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
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.SelectedValue & ")"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
法典没有问题,但不管在下降时我选择什么项目总是作为共同用户(这是本表的第一个记录)。 虽然我检查了html的生成:
<select name="ctl00$MainContent$ddRoles" id="MainContent_ddRoles">
<option value="5">Common User</option>
<option value="6">Developer</option>
<option value="7">Manager</option>
这似乎正确,但我的数据库只有第5号身份证的记录。 谁能帮助我?