dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Save DataGridView record without last emty rows

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    54

    Resolved [RESOLVED] Save DataGridView record without last emty rows

    Hello every one
    Please I really need help
    With Button1 i have this code to prepare my controls
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            DataGridView1.ClearSelection()
            Dim K = DataGridView1.Rows.Add()
            DataGridView1.Rows(DataGridView1.Rows.Count - 1).Selected = True
            Rowindx = K
    
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
    
        End Sub
    After with my Button2 to save data in my
    All works fine .. except always after I save my data I find in my database a last empty rows as shown in this picture .. the line in blue
    My DataGridView1 is at : AllowUserTo AddRows = False
    Please .. how to make to save my data in my DatagridView1 without this last empty rows
    Cordially
    ABE
    Last edited by ABIDINE; Dec 5th, 2019 at 10:31 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,563

    Re: Save DataGridView record without last emty rows

    I think you're going about it all wrong. Your code seems to be filling a datatable and then copying values from the grid and putting them into the datatable.... so where did the values from the grid come from? Personally I'd create the datatable from what ever source, and then bind it to the grid... or rather, bind it to a BindingSource object and then bind that to the DataGridView .... then to add/remove/edit data all of the actions would be on the BindingSource.... which will update the underlying DataTable, and the bound grid. Then, it's simply a matter of reattaching the datatable to the connection and issuing an .Update on the adaptor...



    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    54

    Re: Save DataGridView record without last emty rows

    Thank you techgnome
    yes you are right
    My datagridview1 will be filled by another Button ( BtnFillDdv ) .. that passed some value from the TextBox to this DatagridView .. after that .. i save data with Button2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width