English 中文(简体)
我的网上表格只插入了第一个项目,不管我选择什么。
原标题:My Web Form inserts only the first item in dropdown no matter what I choose

我有两个关系表:包含三类用户角色的简介表(管理者、开发者、共同用户)和用户表,其中载有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号身份证的记录。 谁能帮助我?

最佳回答

各位以对“Load”页的每一个呼吁都具有约束力的方式,再次击毁德林名单中的选择。 你们只需要约束! 反馈。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签