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

x
?
Solved

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

Posted on 2009-05-19
8
Medium Priority
?
2,790 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 2000 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

722 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