Go Premium for a chance to win a PS4. Enter to Win

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,833 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 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
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!

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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…
Suggested Courses

916 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