如何用数据库构建下拉列表?(How to build dropdown list with database?)
我尝试构建与数据库绑定的下拉列表。 我发现了一些我没有找到的错误。 请帮忙,下面是我的代码。
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”无效。
I have try to build dropdown list that bind with database. I found out some errors that i dont really found. Please help, here below is my codes.
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 Iferror found
Invalid column name 'DeptNameFULL'.
最满意答案
您的错误在您的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 " 。
Your error is in your sql statement... The database is looking for a field called "DeptNameFULL" and of course there isn't.
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 "On the second line - you need a space after "Table2.deptname" - so it should be Table2.deptname " instead.
更多推荐
发布评论