Solved

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

Posted on 2009-05-19
8
2,709 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
Independent Software Vendors: 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!

 
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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

749 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