• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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")

  • 2
1 Solution
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..


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
Den2556Author Commented:
Restricted the columns by using the Select SQL statement.

This works


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now