Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I need help inserting records from a bound datagridview control in vb.net

Posted on 2016-10-24
3
Medium Priority
?
66 Views
Last Modified: 2016-11-16
Hi Experts,
I have a DataGrieView control in my VB.Net application which I load bind to a tableadapter programmatically.
I am able to update existing records from the datagridview control to the underlying database, but I am not able to insert\add records from the datagridview control to the database.

What am I doing wrong?  How can I fix this?


Below, I have added my code, and also the error message I get when I try to add the record to the datagridview:

Code
Code image

Error Message
Error Message
Is there a way to programmatically add the ProviderMasterID, when I click on the Drop Down combobox?

Thank you very much in advance,
mrotor
0
Comment
Question by:mainrotor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 41858085
    Private Sub TblProviderBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TblProviderBindingSource.AddingNew
        Dim dv As DataView = TryCast(TblProviderBindingSource.List, DataView)
        Dim rv As DataRowView = dv.AddNew()

        rv("LkLanguageId") = 12345
        e.NewObject = rv
        TblProviderBindingSource.MoveLast()
    End Sub

Open in new window

0
 

Author Comment

by:mainrotor
ID: 41859097
Ark,
You were close, but I kept getting the error below:

Error:
Error i was getting when trying to add a row
I fixed it by adding a line of code and modifying your procedure a little (see code below):
Reference to were I got the additional line of code from:

Link to where I got the additional line of code from.

    Private Sub TblProviderBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TblProviderBindingSource.AddingNew
	Dim bindingSource As BindingSource = CType(sender, BindingSource)	' Added Code
        Dim dv As DataView = TryCast(bindingSource.List, DataView)	                'Modified Code
        Dim rv As DataRowView = dv.AddNew()

        rv("LkLanguageId") = 12345
        e.NewObject = rv
        bindingSource.MoveLast()					                                                  'Modified Code
    End Sub

Open in new window



Thank you very  much.  You will still get the full credit.  I really appreciate your help.  I had been struggling with this issue for quite a bit.

Thanks,
mrotor
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

730 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