0

我有两种不同形式的 2 个不同的 datagridview(1. 客户列表 2. 该客户的付款历史)。当我从表单 1 中单击客户端时,我想使用他的 clientID 来过滤 Form2 上的 datagridview 问题是当我WHERE用作查询时它不显示表,如果我删除WHERE支付表中的所有付款将显示。

客户名单 这是单击表格1中的行时的代码

ElseIf colName = "colViewPayment" Then

        Dim row As DataGridViewRow = datagridviewClient.Rows(e.RowIndex)
        Dim fname As String
        Dim lname As String
        Using cmd As SqlCommand = New SqlCommand("SELECT * FROM tbtClients WHERE ClientID = @ClientID")
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@ClientID", row.Cells("ClientID").Value)
            cmd.Connection = con
            con.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                sdr.Read()
                fname = sdr("ClientFirstName")
                lname = sdr("ClientLastName")
                frmLoanerPaymentHistoryBunifu.NameR.Text = fname + " " + lname
                frmLoanerPaymentHistoryBunifu.CpNo.Text = sdr("ClientMobileNumber").ToString()
                frmLoanerPaymentHistoryBunifu.ClientID.Text = sdr("ClientID").ToString()

            End Using
            con.Close()
            frmLoanerPaymentHistoryBunifu.ShowDialog()


        End Using

在此处输入图像描述 这是用于在付款历史表单 (form2) 中填充数据网格的代码

Private Sub BindGrid()

    Dim CID As String = ClientID.Text
    Dim x As Integer = Convert.ToInt64(CID)

    Using cmd As New SqlCommand("SELECT * FROM PaymentTable WHERE ClientID = '" + ClientID.Text + "'", con)
        cmd.CommandType = CommandType.Text
        Using sda As New SqlDataAdapter(cmd)
            Using dt As New DataTable()
                sda.Fill(dt)

                pDataGrid.AutoGenerateColumns = False

                'Add Columns
                pDataGrid.Columns(0).Name = "PID"
                pDataGrid.Columns(0).DataPropertyName = "PaymentID"

                pDataGrid.Columns(1).Name = "CID"
                pDataGrid.Columns(1).DataPropertyName = "ClientID"

                pDataGrid.Columns(2).Name = "Pdate"
                pDataGrid.Columns(2).DataPropertyName = "PDate"

                pDataGrid.Columns(3).Name = "Pamt"
                pDataGrid.Columns(3).DataPropertyName = "PAmt"

                pDataGrid.Columns(4).Name = "Pren"
                pDataGrid.Columns(4).DataPropertyName = "ReloanDate"

                pDataGrid.Columns(5).Name = "Pcol"
                pDataGrid.Columns(5).DataPropertyName = "PColl"

                pDataGrid.DataSource = dt
            End Using
        End Using
    End Using
End Sub
4

0 回答 0