Edit Datagrid

Posted on 2005-04-13
Last Modified: 2010-05-19
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")

Question by:Den2556
    LVL 25

    Expert Comment

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


    LVL 25

    Accepted Solution

    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

    Author Comment

    Restricted the columns by using the Select SQL statement.

    This works


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now