Hi all,
I have a datagridview in which I add programatically a combobox column with its datasource set to a datatable I fill from a query, then I populate manually (for good reasons) the DGV, but just when I try to add the first row, this error shows up:

Fielld called 'Unidad' does not exist.

Here is the code where I add the combobox column:

unidadDataSet = New DataSet()
query = "select idUnidad,Unidad from catUnidades order by Unidad"
conn = New SqlConnection(connectionString) : conn.Open()
cmd = New SqlCommand(query, conn)

unidadDataAdapter = New SqlDataAdapter
        unidadDataAdapter.SelectCommand = cmd
        unidadDataAdapter.Fill(unidadDataSet)
        With unidadesColumn
            .DataPropertyName = "catUnidades"
            .HeaderText = "UNIT"
            .Width = 80
            .DataSource = unidadDataSet
            .ValueMember = "idUnidad"
            .DisplayMember = "Unidad"
            .Visible = False
        End With
        ReqProdGridView.Columns.Add(unidadesColumn)
        conn.Close()

and here is where I try to add a a row to the ReqProdGridView:

ReqProdGridView.Rows.Clear()
        i = 0
        Try
            query = "select Parte,DescripcionParte,NumeroMaterialProveedor,Precio,Cantidad " & _
            "from detRequisicionesPO dR,db_owner.catpartes CP,catDescripcionesParte DP,relproveedormaterial PM " & _
            "where DR.idparte = CP.idparte and CP.idDescripcionParte = DP.idDescripcionParte " & _
            "and CP.Parte = PM.NumeroMaterial and idProveedor = " & vendorID & " and idrequisicionPO = " & idReq
            conn = New SqlConnection(connectionString) : conn.Open()
            cmd = New SqlCommand(query, conn)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                While dr.Read
                    ReqProdGridView.Rows.Add()
                    ReqProdGridView.Rows(i).Cells(0).Value = dr.GetString(dr.GetOrdinal("Parte"))
                    ReqProdGridView.Rows(i).Cells(1).Value = dr.GetString(dr.GetOrdinal("DescripcionParte"))
                    ReqProdGridView.Rows(i).Cells(2).Value = dr.GetString(dr.GetOrdinal("NumeroMaterialProveedor"))
                    ReqProdGridView.Rows(i).Cells(3).Value = dr.GetDouble(dr.GetOrdinal("Precio"))
                    ReqProdGridView.Rows(i).Cells(4).Value = dr.GetInt32(dr.GetOrdinal("Cantidad"))
                    i = i + 1
                End While
            End If
            dr.Close() : conn.Close()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try

Could someone help me out?

Thanks in advance

Gabriela

So does the field Unidad exist in your database?

Niek

Yes, of course. The field exists on my table and so, I pass the query to the datatable object.

But when adding a row, the error message shows up.

Will that mean that I must fill the combobox column with data after I added all rows I need in my datagridview?

select Parte,DescripcionParte,NumeroMaterialProveedor,Precio,Cantidad " & _            "from detRequisicionesPO dR,db_owner.catpartes CP,catDescripcionesParte DP,relproveedormaterial PM " & _            "where DR.idparte = CP.idparte and CP.idDescripcionParte = DP.idDescripcionParte " & _            "and CP.Parte = PM.NumeroMaterial and idProveedor = " & vendorID & " and idrequisicionPO = " & idReq

Your query does not have a field named unidad.

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.