Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:28+00:00 2026-05-26T18:31:28+00:00

When I insert data from my datagridview to my database an extra row is

  • 0

When I insert data from my datagridview to my database an extra row is inserted at the end which contains no data. How can I overcome this issue. Each time I click on a new line in my datagridview and start the enter data, a new line is enabled below. Is there any way I can stop this blank line being inserted into my database? Thanks, here’s my code…

                    Dim ds As New DataSet 
                    ds.Tables.Add("Main") 

                   Dim col As New DataColumn 

                    Dim dgvCol As New DataGridViewColumn 
                    For Each dgvCol In DataGridView1.Columns 
                        col = New DataColumn(dgvCol.Name) 
                        ds.Tables("Main").Columns.Add(col) 
                    Next 
                    Dim row As DataRow 
                    Dim colcount As Integer = DataGridView1.Columns.Count - 1 

                    For i As Integer = 0 To DataGridView1.Rows.Count - 1 
                        row = ds.Tables("Main").Rows.Add 

                        For Each column As DataGridViewColumn In DataGridView1.Columns 
                            row.Item(column.Index) = DataGridView1.Rows.Item(i).Cells(column.Index).Value 
                        Next 

                    Next 


                    Dim con As New SqlClient.SqlConnection 
                    Dim myCommand As New SqlClient.SqlCommand 

                    Dim dt As New DataTable() 
                    dt = ds.Tables("Main") 

                    For i As Integer = 0 To dt.Rows.Count - 1 

                        Dim myAdapter As New SqlClient.SqlDataAdapter 
                        Dim sql As String = "Insert into details (company, division, date, supplier, material_group, cost, dsc, email, userID, fullName, marketingCode, hccNumber, wbs, qty, currency, timestamp) VALUES ('" & DataGridView1.Rows(i).Cells(company.Name).Value & "', '" & DataGridView1.Rows(i).Cells(division.Name).Value & "','" & calendar & "', '" & DataGridView1.Rows(i).Cells(supplier.Name).Value & "', '" & DataGridView1.Rows(i).Cells(materialGroup.Name).Value & "', '" & DataGridView1.Rows(i).Cells(netprice.Name).Value & "', '" & DataGridView1.Rows(i).Cells(description.Name).Value & "', '" & cmbEmail.SelectedValue & "', '" & id & "', '" & newName & "', '" & DataGridView1.Rows(0).Cells(markCodes.Name).Value & "', '" & DataGridView1.Rows(0).Cells(hccNumber.Name).Value & "', '" & DataGridView1.Rows(i).Cells(wba.Name).Value & "', '" & DataGridView1.Rows(i).Cells(quantity.Name).Value & "', '" & DataGridView1.Rows(i).Cells(currency.Name).Value & "', '" & nowDate & "')" 
                        myCommand.Connection = con 
                        myCommand.CommandText = sql 
                        myAdapter.InsertCommand = myCommand 
                        myCommand.Connection.Open() 
                        myCommand.ExecuteNonQuery() 
                        myCommand.Connection.Close() 

                    Next.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:31:29+00:00Added an answer on May 26, 2026 at 6:31 pm

    You’ll need your check your row for values in your loop try checking each cell (or a specific cell) for DBNull.Value before saving it. Alternatively you can set AllowUsersToAddRows to false to prevent the blank row from showing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i insert each time a diffrent row in datatable? The data table
i want to insert data from an excel file into a local database in
I have a DataGridView that displays data from a MS Access database. I'm using
I have a DataGridView, which loads data from mdb Access table The grid only
I insert data from a typed dataset into my MSSQL database by using SqlBuldCopy
i try to insert data from database to Jtable there is my code: private
I am creating windows application to insert data from Excel file into database. My
We insert data from a database into a word-document (Word 2007). There are tables
Im trying to insert data from a textbox to my database, and it throwing
I need to insert data from table1 into table2. However, I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.