none
數據綁定第2次查詢出錯 RRS feed

  • 一般討論

  • Public Class form1

        Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
            '多角度查詢條件
            If e.Button Is ToolBarButton1 Then
                tb_po_big_type.BackColor = Color.Aqua
                tb_po_big_type_nm.BackColor = Color.Aqua
                DataSet11.Clear()
                '多角度查詢條件
                ToolBarButton1.Enabled = True
                '多角度開始查詢
                ToolBarButton2.Enabled = True
            End If

            '開始查詢
            If e.Button Is ToolBarButton2 Then
                tb_po_big_type.BackColor = Color.White
                tb_po_big_type_nm.BackColor = Color.White
                Dim db As database = New database
                DataSet11.Clear()
                Dim strsql As String
                strsql = strsql & "select * from po_type_list where 1=1"
                If tb_po_big_type.Text <> "" Then strsql = strsql & " and po_big_type like '%" & tb_po_big_type.Text & "%'"
                If tb_po_big_type_nm.Text <> "" Then strsql = strsql & " and po_big_type_nm like '%" & tb_po_big_type_nm.Text & "%'"
                strsql = strsql & " order by po_big_type,po_mid_type"
                SqlDataAdapter1.SelectCommand.CommandText = strsql
                SqlDataAdapter1.Fill(DataSet11)
                DataGrid1.AllowNavigation = True
                DataGrid1.AllowSorting = True
                Me.DataSet11.po_type_list.Columns(0).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(1).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(2).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(3).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(4).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(5).MaxLength = 100
                Me.DataSet11.po_type_list.Columns(0).ColumnName = "大分類代號"
                '多角度條件
                ToolBarButton1.Enabled = True
         endif
        End Sub
    End Class

     

    我定義了一個form,一個datagrid並指定datasource和datamember,定義了一個toolbar和兩個button,分別是button1和button2,其中button1用來重新查詢清除資料下查詢條件,button2用來查詢.

    問題來了.

          第一次查詢出來結果ok,第2次點button2出現

    "請放鬆或關閉資料集中的條件約束"

    "請先清除資料集"

    以上請高手指點

    並請教:如何定義每個datagrid查詢出來的資料寬度?

    2006年12月4日 上午 02:53