• 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?

Regards,
Denise

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

       
0
Den2556
Asked:
Den2556
  • 2
1 Solution
 
RonaldBiemansCommented:
How did you restrict the columns, If you just hide the columns in the grid than you should have no problems

like


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..

Me.DataGrid1.TableStyles.Add(ts)



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

This works

Thanks
0

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