Solved

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

Posted on 2009-05-19
8
2,637 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
  • 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
 
LVL 1

Author Comment

by:demoniumz
ID: 24420961
where to  find these?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now