【问题标题】:Dropdownlist binded data code behind shows blank rows下拉列表绑定数据代码后面显示空白行
【发布时间】:2015-01-21 03:32:43
【问题描述】:

在我的 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 字段中有一些空白行。数据被绑定但有空格,因为有些行的 ID1 为空白,如下所示

【问题讨论】:

    标签: asp.net


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      相关资源
      最近更新 更多