Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have doing windows application using vb.net 2010. i have 1 form, 1 gridview, 1 update/save button, 1 refresh button. in my code i can populate only 20 records and when i click next button it shows me the next 20 records. but my problem is code for update/save and refresh button. that means users can edit/delete/update/save data from the gridview. what i need is based on my code. thank you for your help. here is the code

VB
Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
Try
        
  conn = GetConnect()
            conn.Open()

            str = "select [DocId],[Description]      ,[Address]      ,[NoOfPages]      ,[SendOrReceived]      ,[SentDate]      ,[ReceivedDate]      ,[ForwardedWorkingUnit]      ,[Attachements]      ,[ForwardedDate]      ,[ReceivedBy]      ,[LetterWrittenDate]      ,[DocPath]  FROM [Data].[dbo].[mytable]ORDER BY Id DESC"

            com = New SqlCommand(str, conn)

            oledbda = New SqlDataAdapter(com)

            ds = New DataSet

            oledbda.Fill(ds, i, 20, "mytable")

            DataGridView1.DataSource = ds

            DataGridView1.DataMember = "mytable"

            conn.Close()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try
end sub


code for next button

VB
Private Sub Nextrecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nextrecord.Click
        
        i = i + 20

        If i > 23 Then

            i = 18

        End If

        ds.Clear()

        oledbda.Fill(ds, i, 20, "mytable")
    End Sub


code for previous button

VB
Private Sub PreviousRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousRecord.Click
        
       i = i - 20

        If i <= 0 Then

            i = 0

        End If

        ds.Clear()

        oledbda.Fill(ds, i, 20, "mytable")

    End Sub
Posted
Comments
[no name] 20-Aug-13 9:58am    
Not clear what your problem is.
ZurdoDev 20-Aug-13 12:29pm    
What's your question?
Mr.TMG 20-Aug-13 21:34pm    
If I understand correctly, the title of this post implies that you are not sure how to save changes to a particular row in the data table. If that's the case then I would suggest simply passing and UPDATE command to SQL using your table adapter.

UPDATE "[col]"="@value" ON [TABLE] WHERE ({DOCID] = @DOCID)

My question is this; What is the exact problem you are having? passing the data to the data base, determining which rows to update? I think, as the others have said, this will require a little more input from you.
Beiniam 21-Aug-13 2:54am    
my question is
1) how can i update the database through datagridview based on my datasate?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900