Dropdownlist绑定后面的数据代码显示空白行

时间:2014-11-23 09:48:03

标签: asp.net

在我的asp.net中,带有访问数据库的Web背后的VB代码。我正在使用此代码绑定数据。

Dim comd As New OleDbCommand("SELECT ID1 FROM [Tak1] Where Section_='" + sectxt.Text + "' and status_='Open' and ID1<>""", con1)
Dim daa As New OleDbDataAdapter(cmd)
Dim dss As New DataSet()
daa.Fill(dss)
DropDownList3.Items.Clear()
DropDownList3.DataSource = dss
DropDownList3.DataTextField = "ID1"
DropDownList3.DataBind()
DropDownList3.Items.Insert(0, New ListItem("Please Select", "NA"))

数据库在ID1字段中有一些空行。 data得到绑定但有空格,因为有一些空行ID1的行如下所示

enter image description here

1 个答案:

答案 0 :(得分:1)

你的意思是写:

Dim comd As New OleDbCommand("SELECT ID1 FROM [Tak1] Where Section_='" + sectxt.Text + "' and status_='Open' and ID1<>""""", con1)

或者,(或者优选地),

Dim comd As New OleDbCommand("SELECT ID1 FROM [Tak1] Where Section_='" + sectxt.Text + "' and status_='Open' and ID1<>''", con1)

(您可能忘记添加所需的所有引号,因为"""的转义

有关类似问题,请参阅here