2017-04-12 38 views
0

我嘗試構建與數據庫綁定的下拉列表。我發現了一些我沒有發現的錯誤。請幫助,下面是我的代碼。如何建立與數據庫的下拉列表?

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「。

回答

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 "代替。

+0

謝謝。它工作。 – user3759016