如何使用每个....下一个文本框在vb.net中

时间:2017-06-28 14:22:15

标签: html sql vb.net

我想使用"为每个......下一个"通过文本框执行我的查询,所以我想在文本框中输入值,但我只获得文本框的多个值的一个值

Try

    For Each i In TextBox2.Text
        'Create the SelectCommand.

        cmd = New OdbcCommand("select b.id_detail_polygon,b.mappe_3,b.type_d_affaire,b.consistance,b.nbr_borne ,num_bornes,a.x,a.y,b.superficie_cs  from point a right join (select (dp).path[1] d1,(dp).path[2] d2,(dp).geom d3 from (select st_dumppoints(geom) dp from polygon where id_detail_polygon ='" & i & "')a)dptable on st_equals(a.geom,dptable.d3),polygon b where id_detail_polygon='" & i & "' limit ((select st_npoints(geom) from polygon where id_detail_polygon ='" & i & "')-1)", cnDb) ' & _
        adDb = New OdbcDataAdapter(cmd)
        adDb.Fill(dsDB, ComboBox1.Text)
        DataGridView2.DataSource = dsDB
        DataGridView2.DataMember = ComboBox1.Text
        DataGridView2.DataSource = dsDB.DefaultViewManager

    Next

Catch ex As Exception
     MsgBox("ERROR :" + ex.Message)
Finally

End Try

enter image description here

1 个答案:

答案 0 :(得分:0)

目前尚不清楚TextBox中的数据如何工作。你需要更具体。是逗号分隔的吗?空间划界?

我会假设以逗号分隔。这段代码可以帮助您入门:

Dim IDs() As Stringg
Dim sql As String = _
     "select b.id_detail_polygon,b.mappe_3,b.type_d_affaire,b.consistance,b.nbr_borne, num_bornes,a.x,a.y,b.superficie_cs " & _
     "from point a " & _
     "right join ( " & _
         "select (dp).path[1] d1,(dp).path[2] d2,(dp).geom d3 " & _
         "from ( " & _
             "select st_dumppoints(geom) dp " & _
             "from polygon " & _
             "where id_detail_polygon= ? " & _
         ") a " & _
      ") dptable on st_equals(a.geom,dptable.d3)" & _ 
      "inner join polygon b on id_detail_polygon= ? " & _ 
      "limit (select st_npoints(geom) from polygon where id_detail_polygon= ? )-1"


DataGridView2.DataMember = ComboBox1.Text
DataGridView2.DataSource = dsDB.DefaultViewManager

Using fields As New TextFieldParser(TextBox.Text), _
      cmd As New OdbcCommand(sql, cnDb), _
      adDb As New OdbcDataAdapter(cmd)      

    fields.Delimiters = New String() {","}
    'Guessing at parameter type here: an id value is usually an int
    cmd.Parameters.Add("?", OdbcType.Int)
    cmd.Parameters.Add("?", OdbcType.Int)
    cmd.Parameters.Add("?", OdbcType.Int)

    ' We know in advance there's only one row
    IDs = fields.ReadFields()
    ' but loop through ALL of the fields in that row
    For Each ID As Integer In IDs.Select(Function(i) Integer.Parse(i))
        cmd.Parameters(0) = ID
        cmd.Parameters(1) = ID
        cmd.Parameters(2) = ID 

        adDb.Fill(dsDB, ComboBox1.Text) 
        DataGridView2.DataSource = dsDB  
    Next Id

End Using

但它仍有一个重要缺陷。 datagridview将仅显示文本框中 last 记录的信息,因为循环的每次迭代都会覆盖上一次迭代中的数据。

我无法在这个问题的背景下为你解决这个问题。这将要求您回到应用程序的这一部分的整个设计的绘图板。