'i am trying to get f_name + m_name + l_name three diferent columns combined from data grid view on cell content click into combobox.

Private Sub bugdgv_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles bugdgv.CellContentDoubleClick
        Dim row As Integer = bugdgv.CurrentCell.RowIndex
        frmbug.bugcmbdeliver.Items.Clear()
        Try
            obcon.cmd.CommandText = "select d.del_name from deliver_project d,bug b where b.bug_id=d.del_id and d.del_name='" & bugdgv.Item("del_name", row).Value & "'"
            obcon.con.Open()
            Dim dr As SqlDataReader
            dr = obcon.cmd.ExecuteReader
            If (dr.Read) Then
                frmbug.bugcmbdeliver.Items.Add(0)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            obcon.con.Close()
        End Try
        frmbug.bugcmbassign.Items.Clear()
        Try
            'obcon.cmd.CommandText = "select c.f_name from deliver_project d,bug b where b.bug_id=d.del_id and d.del_name='" & bugdgv.Item("del_name", row).Value & "'"
            obcon.cmd.CommandText = "select c.f_name + ' '+ c.l_name as 'name' from contact c,bug b where b.con_id=d.con_id and d.f_name + ' ' + d.l_name='" & bugdgv.Item("f_name + ' ' + l_name", row).Value
            obcon.con.Open()
            Dim dr As SqlDataReader
            dr = obcon.cmd.ExecuteReader
            If (dr.Read) Then
                frmbug.bugcmbassign.Items.Add(0)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            obcon.con.Close()
        End Try
        frmmain.BugsToolStripMenuItem_Click(sender, e)
        frmbug.bugbtnedit.Show()
        frmmain.bugs.bid = bugdgv.Item("bug_id", row).Value
        frmmain.bugs.bugtxtname.Text = bugdgv.Item("bug_name", row).Value
        frmmain.bugs.bugrtbdescription.Text = bugdgv.Item("bug_descrip", row).Value
        frmmain.bugs.bugcmbdeliver.Text = bugdgv.Item("del_name", row).Value
        'frmmain.bugs.bugcmbassign.Text = bugdgv.Item("f_name", row).Value
        'frmmain.bugs.bugcmbassign.Text = bugdgv.Item("l_name", row).Value
        frmmain.bugs.bugcmbstatus.Text = bugdgv.Item("bug_status", row).Value
        frmmain.bugs.bugdtpdate.Text = bugdgv.Item("bug_date", row).Value
        frmmain.bugs.bugtxtprojnm.Text = bugdgv.Item("bug_p_name", row).Value
        frmmain.bugs.bugtxtwork.Text = bugdgv.Item("bug_name", row).Value
        Me.Close()
end sub

Dani AI

Generated

Short answer: do not re-query the database for a full name if the grid already has the name parts. Read the cells from the clicked row, join them safely (handle null/empty middle names), then put the result into the combo box. is right that a JOIN belongs in the SQL when you must fetch data that is not present in the grid; was right to ask for clarification — the solution depends on whether your DataGridView already contains f_name, m_name and l_name or not.

Example (robust, reads from the DataGridView and creates a null-safe full name):

Private Sub bugdgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) _
    Handles bugdgv.CellDoubleClick

    If e.RowIndex < 0 Then Return

    Dim r = bugdgv.Rows(e.RowIndex)
    Dim fn = If(r.Cells("f_name").Value IsNot Nothing, r.Cells("f_name").Value.ToString().Trim(), "")
    Dim mn = If(r.Cells("m_name").Value IsNot Nothing, r.Cells("m_name").Value.ToString().Trim(), "")
    Dim ln = If(r.Cells("l_name").Value IsNot Nothing, r.Cells("l_name").Value.ToString().Trim(), "")

    Dim parts As New List(Of String)
    If fn <> "" Then parts.Add(fn)
    If mn <> "" Then parts.Add(mn)
    If ln <> "" Then parts.Add(ln)

    Dim fullName = String.Join(" ", parts.ToArray())

    frmbug.bugcmbassign.Items.Clear()
    frmbug.bugcmbassign.Items.Add(fullName)
    frmbug.bugcmbassign.SelectedIndex = 0
End Sub

If the grid is bound to a DataTable, consider adding a computed column (FullName) at the data source so the UI can show one column. If you must re-query the DB, build the full name in SQL with null-safe functions (ISNULL/COALESCE) and use a parameterized query — never concatenate user values into SQL. Final checks: confirm your DataGridView column names match (DataPropertyName vs HeaderText), handle DBNull.Value, and avoid CurrentCell.RowIndex in event handlers — prefer e.RowIndex for accuracy.

Recommended Answers

All 6 Replies

You use an inner join to combine two tables. A very good explanation of joins (inner and outer) with clear examples can be found here

sorry i can get your point , you want to show 3 columns in grid like this f_name + m_name + l_name in a single cell , ? and 2nd thing what i understand is that you want to show 3 columns of your grid in a combo in this way f_name + m_name + l_name ,
please rephrase you question.

Regards

As w says, the more info the better. It would help if you could tell us the table structures and (in English) what data you wan to display as in (for example)

I want to display the employee ID and name for every employee who has sold more than 8 cars in the given month (which would require a join of the employee table and the sales table).

sorry i can get your point , you want to show 3 columns in grid like this f_name + m_name + l_name in a single cell , ? and 2nd thing what i understand is that you want to show 3 columns of your grid in a combo in this way f_name + m_name + l_name ,
please rephrase you question.

Regards

'ya sir i want to show 3 columns of my grid in a combo box on clicking on raw.cellcontent click.

Reread my last post.

Reread my last post.

' Here we r geting data from contact tabel.in a grid view and associate it with specific bug.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.