VB.NET Datagrid Delete/Update

Posted on 2009-04-22
Last Modified: 2012-05-06
I created a windows form application that has a datagrid.  I want to set is to that users can delete or update.  However, when updating/deleting, it is not doing anything.  Below is my code that I use for pulling data into the datagrid.  What do I need to set so that user can update/delete line items?
Dim strConnect As New SqlClient.SqlConnection("data source=SERVERNAME;persist security info=False;initial catalog=DATABASE;UID=sa;PWD=PASSWORD")

        Dim dt As New DataTable("")

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("NOTE", strConnect)

        Dim adapter As New SqlClient.SqlDataAdapter

        cmd.CommandType = CommandType.StoredProcedure

        'Enter parameter

        Dim myParam1 As SqlClient.SqlParameter = cmd.Parameters.Add("@ID", SqlDbType.NVarChar, 10)

        myParam1.Value = txtID.Text

        Dim myParam2 As SqlClient.SqlParameter = cmd.Parameters.Add("@START", SqlDbType.DateTime)

        myParam2.Value = dtpStart.Text

        Dim myParam3 As SqlClient.SqlParameter = cmd.Parameters.Add("@END", SqlDbType.DateTime)

        myParam3.Value = dtpEnd.Text

        Dim myParam4 As SqlClient.SqlParameter = cmd.Parameters.Add("@SEARCH", SqlDbType.NVarChar, 50)

        myParam4.Value = txtSearch.Text

        'open database


        'assign select command

        adapter.SelectCommand = cmd

        adapter.SelectCommand.Connection = strConnect

        'fill datatable



        Catch ex As Exception


        End Try

        'fill the grid

        dgNotes.DataSource = dt

Open in new window

Question by:holemania
    LVL 6

    Expert Comment

    you would need to set the UpdateCommand and DeleteCommand like you have set the SelectCommand.

    LVL 10

    Expert Comment

    Usually i setup my stuff this way...  in my aspx, i place a datagrid, an sqldatasource.  In the SqlDataSource, i define and UpdateCommand and SelectCommand.  

    I've never tried with adapter & fill...

    Accepted Solution

    Restructured my code and found a few articles online with insert/update/delete examples using with windows form.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now