Edit Datagrid

I have an editable Datagrid on a form.
Currently the Datagrid is populated with the all the columns from a table.   I only want to display two columns on the grid, however when I restrict the number of columns I can no longer save the details back to the database.

Is it possible to use a SQL Select statments and have an editable Datagrid?


        sConnect = "Provider=MSDAORA.1;Password=gbs;User ID=gbs;Data Source=busd;"
        OLEConn.ConnectionString = sConnect
        cmd.Connection = OLEConn
        mstrSQL = "SELECT GroupID, Category, PolicyId, BSDate, Rundate" & _
            " FROM ""GBS"".tblDetContribCurrent Where " & _
            "(GroupId = " & cGroupDetails.pstrGroupNo & ") "
        cmd.CommandText = mstrSQL

        da.SelectCommand = cmd
        da.Fill(ds, "tblDetContribCurrent")

To Save Details
         Dim s As OleDb.OleDbCommandBuilder
         s = New OleDb.OleDbCommandBuilder(da)

          da.Update(ds, "tbldetcontribcurrent")

Who is Participating?
RonaldBiemansConnect With a Mentor Commented:
Also I would not advice you to use the commandbuilder.  

Why: The commandbuilder object reauires a roundtrip to the database to read the information it needs, real world application can't afford this overhead. Write the commands yourself or drag an adapter from toolbox
How did you restrict the columns, If you just hide the columns in the grid than you should have no problems


Dim ts As New DataGridTableStyle
ts.MappingName = ds.tables("tblDetContribCurrent").TableName

        ts.GridColumnStyles(1).Width = 0 'hides the 2 column
        ts.GridColumnStyles(2).Width = 0 'hides the 3 column
        ts.GridColumnStyles(4).Width = 0 'hides the 5 column ETC..


Den2556Author Commented:
Restricted the columns by using the Select SQL statement.

This works

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.

All Courses

From novice to tech pro — start learning today.