Solved

Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataSet'.

Posted on 2009-05-19
8
2,742 Views
Last Modified: 2013-11-26
hello  i am  tried to add values from textboxes to  datagridview and i get error

Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataSet'.

what these mean.I am using ms access 2003 linked with vb 2005 and i  using binding navigator

can anyone tell me what is the problem.The line that i get error is  Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
       
        Dim bsource As BindingSource = Me.PurchasedetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
        Dim purchasedetailstable As New DataTable
        Dim dr As DataRow = ds.Tables("purchaseDetails").NewRow
        dr("PurchaseID") = PurchaseIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text()
        dr("Productname") = ProductNameTextBox.Text
        dr("Total") = Convert.ToDecimal(UnitPriceTextBox.Text.ToString()) * Convert.ToDecimal(QuantityTextBox.Text.ToString())
 
        ds.Tables("purchaseDetails").Rows.Add(dr)

Open in new window

0
Comment
Question by:demoniumz
[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
  • 4
  • 4
8 Comments
 
LVL 1

Accepted Solution

by:
rdeputat earned 500 total points
ID: 24420743
try

Dim ds As DataSet = DirectCast( DirectCast(bsource.DataSource, BindingSource ).DataSource, DataSet)
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24420858
is not giving me the previous error unable to cast but nothing appear when i add a product in the datagridview
0
 
LVL 1

Expert Comment

by:rdeputat
ID: 24420892
give me source code InitializeComponent();
0
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
LVL 1

Author Comment

by:demoniumz
ID: 24420961
where to  find these?
0
 
LVL 1

Expert Comment

by:rdeputat
ID: 24421014
Public Class Form1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
End Class
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24421016
tell me and i give you  at the night i must go to work now thnks
0
 
LVL 1

Expert Comment

by:rdeputat
ID: 24421061
send me full source code dep@dextechnology.com
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24424411
sent allready
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

729 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