【问题标题】:How to build dropdown list with database?如何用数据库建立下拉列表?
【发布时间】:2017-04-12 02:26:15
【问题描述】:

我尝试建立与数据库绑定的下拉列表。我发现了一些我没有真正发现的错误。请帮忙,下面是我的代码。

 strSQL = "SELECT distinct table1.DeptName FROM Table1 " & _
                        "FULL JOIN Table2 on table1.DeptName = Table2.deptname" & _
                        "FULL JOIN Table3 on Table1.deptname = table3.DeptName " & _
                        "Where table1.deptname is not null order by table1.deptname "
            Common.OpenConn()
            Common.execReader(strSQL, params, dt, Common.txn)

            If dt.Rows.Count > 0 Then
                DropDownListDept.DataSource = dt
                DropDownListDept.DataTextField = "DeptName"
                DropDownListDept.DataValueField = "DeptName"
                DropDownListDept.DataBind()
                DropDownListDept.Items.Insert(0, New ListItem("Select Department Name", "0"))
            End If

发现错误

列名“DeptNameFULL”无效。

【问题讨论】:

    标签: sql asp.net vb.net


    【解决方案1】:

    您的错误在您的 sql 语句中...数据库正在寻找一个名为“DeptNameFULL”的字段,当然没有。

    strSQL = "SELECT distinct table1.DeptName FROM Table1 " & _
                        "FULL JOIN Table2 on table1.DeptName = Table2.deptname" & _
                        "FULL JOIN Table3 on Table1.deptname = table3.DeptName " & _
                        "Where table1.deptname is not null order by table1.deptname "
    

    在第二行 - “Table2.deptname”之后需要一个空格 - 所以它应该是 Table2.deptname "

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      相关资源
      最近更新 更多