none
請問如何將某個欄位清除或隱藏呢? RRS feed

  • 問題

  • 一開始在SqlCommand的尾端寫WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'",是因為在Eqbath_Form中有一個TextBox2是要顯示輸入的值是和BatchNo(批號)一樣的值,所以才加了這段語法,但是執行在畫面上是不要有這個欄位的,所以要將它清除或隱藏。

    在TextBox2_TextChanged有寫了 DataGridView3.Columns(7).Visible = False,將最後一個欄位(7)給隱藏起來,這是成功的,所以在Eqbatch_Load想說也寫一樣的語法,但是執行後,畫面上還是會出現BatchNo這行。

    請問我是那裡寫錯呢??請各位大大幫忙看一下,指導我.........謝謝!!

     

    有試過在SqlCommand不加WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'"這行,但是執行出來的畫面,還是有BatchNo?是為什麼呢?在SqlCommand都沒有給它連線指令了,為什麼還是會出現呢?

    不懂...還是小妹我誤會它的意思了,可以的話,也請幫忙回答我這個意思......謝謝!!

    程式碼區塊

    Private Sub Eqbatch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     '查詢物料批號庫存位置DataGridView
            Dim command As New SqlClient.SqlCommand("SELECT  A_Component.ComponentID AS 物料編號,B_CprPInvertory.LocationID AS 物料格編號,B_CprPInvertory.LocUpID AS 儲位編號,B_CprPInvertory.LocTopID AS 倉庫編號,B_CprPInvertory.DPNum AS 庫存量,A_Component.Component AS 物料名稱,A_Component.UPrice AS 批號單價,B_CprPInvertory.BatchNo FROM A_Component INNER JOIN  B_CprPInvertory ON A_Component.ComponentID = B_CprPInvertory.ComponentID WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'", cn)
            Dim x As Integer
            da.SelectCommand = command
            da.Fill(ds, "Component3")
            DataGridView3.Columns.Clear()
            For x = 0 To ds.Tables("Component3").Columns.Count - 1
                DataGridView3.Columns.Add(ds.Tables("Component3").Columns(x).Caption, ds.Tables("Component3").Columns(x).ColumnName.ToString)
            Next
            If TextBox2.Text.Length = 10 Then
                DataGridView3.DataSource = ds.Tables("Component3")
                DataGridView3.Columns(7).Visible = False
            End If
        End Sub

     

     

    2007年12月6日 上午 05:52

解答

  • 程式碼區塊

    Private Sub Eqbatch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     '查詢物料批號庫存位置DataGridView
            Dim command As New SqlClient.SqlCommand("SELECT  A_Component.ComponentID AS 物料編號,B_CprPInvertory.LocationID AS 物料格編號,B_CprPInvertory.LocUpID AS 儲位編號,B_CprPInvertory.LocTopID AS 倉庫編號,B_CprPInvertory.DPNum AS 庫存量,A_Component.Component AS 物料名稱,A_Component.UPrice AS 批號單價,B_CprPInvertory.BatchNo FROM A_Component INNER JOIN  B_CprPInvertory ON A_Component.ComponentID = B_CprPInvertory.ComponentID WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'", cn)
            Dim x As Integer
            da.SelectCommand = command
            da.Fill(ds, "Component3")

           

           ds.Tables("Component3").Columns.Remove("BatchNo")
           

            DataGridView3.Columns.Clear()
            For x = 0 To ds.Tables("Component3").Columns.Count - 1
                DataGridView3.Columns.Add(ds.Tables("Component3").Columns(x).Caption, ds.Tables("Component3").Columns(x).ColumnName.ToString)
            Next
            If TextBox2.Text.Length = 10 Then
                DataGridView3.DataSource = ds.Tables("Component3")
                DataGridView3.Columns(7).Visible = False
            End If
        End Sub

     

     

     

    2007年12月6日 上午 06:10
    版主

所有回覆

  • Dim command As New SqlClient.SqlCommand("SELECT  A_Component.ComponentID AS 物料編號,B_CprPInvertory.LocationID AS 物料格編號,B_CprPInvertory.LocUpID AS 儲位編號,B_CprPInvertory.LocTopID AS 倉庫編號,B_CprPInvertory.DPNum AS 庫存量,A_Component.Component AS 物料名稱,A_Component.UPrice AS 批號單價,B_CprPInvertory.BatchNo FROM A_Component INNER JOIN  B_CprPInvertory ON A_Component.ComponentID = B_CprPInvertory.ComponentID WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'", cn)

     

     

    你的語法裡面就有包含 BatchNo 在,所以 datagridview 就自動幫妳產生 BatchNo 欄位

     

    要隱藏的話請建議指定欄位名稱的方式,不要用 index。

    Ex.  DataGridView3.Columns["BatchNo"].Visible = false;

     

    2007年12月6日 上午 06:02
  • 程式碼區塊

    Private Sub Eqbatch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     '查詢物料批號庫存位置DataGridView
            Dim command As New SqlClient.SqlCommand("SELECT  A_Component.ComponentID AS 物料編號,B_CprPInvertory.LocationID AS 物料格編號,B_CprPInvertory.LocUpID AS 儲位編號,B_CprPInvertory.LocTopID AS 倉庫編號,B_CprPInvertory.DPNum AS 庫存量,A_Component.Component AS 物料名稱,A_Component.UPrice AS 批號單價,B_CprPInvertory.BatchNo FROM A_Component INNER JOIN  B_CprPInvertory ON A_Component.ComponentID = B_CprPInvertory.ComponentID WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'", cn)
            Dim x As Integer
            da.SelectCommand = command
            da.Fill(ds, "Component3")

           

           ds.Tables("Component3").Columns.Remove("BatchNo")
           

            DataGridView3.Columns.Clear()
            For x = 0 To ds.Tables("Component3").Columns.Count - 1
                DataGridView3.Columns.Add(ds.Tables("Component3").Columns(x).Caption, ds.Tables("Component3").Columns(x).ColumnName.ToString)
            Next
            If TextBox2.Text.Length = 10 Then
                DataGridView3.DataSource = ds.Tables("Component3")
                DataGridView3.Columns(7).Visible = False
            End If
        End Sub

     

     

     

    2007年12月6日 上午 06:10
    版主
  • 程式碼區塊
    Dim command As New SqlClient.SqlCommand("SELECT  A_Component.ComponentID AS 物料編號,B_CprPInvertory.LocationID AS 物料格編號,B_CprPInvertory.LocUpID AS 儲位編號,B_CprPInvertory.LocTopID AS 倉庫編號,B_CprPInvertory.DPNum AS 庫存量,A_Component.Component AS 物料名稱,A_Component.UPrice AS 批號單價,B_CprPInvertory.BatchNo FROM A_Component INNER JOIN  B_CprPInvertory ON A_Component.ComponentID = B_CprPInvertory.ComponentID WHERE B_CprPInvertory.BatchNo  like '%" + Me.TextBox2.Text + "%'", cn)

     

     


    直接把紅色的字刪除就可以了


    當where條件的欄位,沒有一定要select出來
    2007年12月6日 上午 06:22
  • 謝謝小朱、chhuang~~~~

    這樣更懂意思了。謝謝!

     

    2007年12月6日 上午 06:25