Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

VB.NET Datagrid Delete/Update

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
        strConnect.Open()
 
        'assign select command
        adapter.SelectCommand = cmd
        adapter.SelectCommand.Connection = strConnect
 
        'fill datatable
        Try
            adapter.Fill(dt)
        Catch ex As Exception
            MessageBox.Show(ex.GetBaseException.Message)
        End Try
 
        'fill the grid
        dgNotes.DataSource = dt

Open in new window

0
holemania
Asked:
holemania
1 Solution
 
mvgeertruyenCommented:
you would need to set the UpdateCommand and DeleteCommand like you have set the SelectCommand.

rgds
0
 
Christian de BellefeuilleProgrammerCommented:
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...
0
 
holemaniaAuthor Commented:
Restructured my code and found a few articles online with insert/update/delete examples using vb.net with windows form.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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