How to bind a cell in a datagrid to a field in a database table

I'm looking to bind a cell in a data grid to a database field in a database table. I'm using an ODBC Connection to connect to a local access database.
carter_jlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hatem72Commented:

            Dim nColCombo1 As New DataGridViewComboBoxColumn
            With nColCombo1
                .HeaderText = "Item PartNo"
                .Name = "Col_ItemPartNo"
                Result = clsData.FillCombo(nColCombo1, "Items", "ItemId", "ItemPartNo", "Select * From Items ")

                .Width = 100
                .DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
                .AutoComplete = True
                .Visible = True

            End With : dGrid.Columns.Add(nColCombo1)


here is my function :

 Public Function FillCombo(ByRef cBox As Object, ByVal Tbl As String, ByVal IdFld As String, ByVal NameFld As String, ByVal SqsString As String) As String


        Try
            ' cBox ur ComboBox    
            ' v_ConnectionString Connection String
            ' Tbl  ur table ( Or View ) name
            ' IdFld  DisplayMember Field
            ' NameFld DisplayMember Field
            ' SqsString Select statment

            Dim Conn As SqlConnection = New SqlConnection(v_ConnectionString)
            Dim Comm As SqlCommand = New SqlCommand(SqsString, Conn)
            Comm.Connection = Conn
            Comm.CommandText = SqsString ' "commandtorun"
            Comm.CommandType = CommandType.Text
            Dim DS As DataSet = New DataSet()

            Dim DA As New SqlDataAdapter(Comm)
            Conn.Open()
            DA.Fill(DS, Tbl)

            Dim dt As New DataTable
            dt.Columns.Add(NameFld, GetType(System.String))
            dt.Columns.Add(IdFld, GetType(System.String))

            With cBox
                .DataSource = DS.Tables(Tbl)  
                .DisplayMember = NameFld
                .IdFld = IdFld
            End With


            Call ClossConn(Conn) ' Closs Current Connection

            Return 0
        Catch ex As Exception

            Return ex.Message

        End Try
    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.