none
how to replace DataTable from (Dim dt As New DataTable) to (Data table Wizard) ? RRS feed

  • Question

  • I use code :

    Dim dt As New DataTable
            With dt
                .Columns.Add("ID")
                .Columns.Add("names")
                .Columns.Add("C1")
                .Columns.Add("C2")
                .Columns.Add("C3")
                .Columns.Add("C4")
                .Columns.Add("TotalC")
            End With
            For Each dr As DataGridViewRow In Me.CalculationDataGridView.Rows
                dt.Rows.Add(dr.Cells("ID").Value, dr.Cells("names").Value, dr.Cells("C1").Value, dr.Cells("C2").Value, dr.Cells("C3").Value, dr.Cells("C4").Value, dr.Cells("TotalC").Value)
            Next
    
            Dim rptdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
            rptdoc = New CrystalReportCount
            rptdoc.SetDataSource(dt)
    
            CRCountTotal.CrystalReportViewer1.ReportSource = rptdoc
            CRCountTotal.ShowDialog()
            CRCountTotal.Dispose()

    I want put my Data table(Calculation) instead of(Dim dt As New DataTable) In the example above .

    my data table :


    • Edited by srajmuneer Wednesday, October 25, 2017 2:47 PM
    Wednesday, October 25, 2017 2:45 PM

Answers

  • Hi srajmuneer,

    If you use TableAdapter to fill datagridview, you will see that there are some columns name like XXXXDataGridViewTextBoxColumn in the datagridview, like this:

    You can also see these columns name in datagridview in Form.Designer.vb, these are not same as the HeaderText in DataGridview. So you will get this error when you find some value by headerText.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Thursday, October 26, 2017 10:36 AM
    Thursday, October 26, 2017 8:13 AM
    Moderator

All replies

  • Is there a reason you want to use the data wizard method?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, October 25, 2017 2:58 PM
    Moderator
  • thank you  Kareninstructor , when use data wizard method and run code In the example above show error :

    Wednesday, October 25, 2017 3:31 PM
  • How are your creating your DataGridViewColumns e.g. in code or in the DataGridView designer? If in the DataGridView designer check the column names, verify that ID column exists or it's named something like IdColumn etc.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, October 25, 2017 3:48 PM
    Moderator
  • when use (Dim connectionString As String = "") to show data and use In the example above don't show Error

    but use (Me.CalculationTableAdapter.Fill(Me.TestDataSet.Calculation) to show data and use In the example above show Error

    I want show crystal report fro DGV

    Wednesday, October 25, 2017 4:10 PM
  • The difference between using an OleDb.Connection and OleDb.Command and TableAdapter is that the TableAdapter method data from the database must match the strong typed classes generated for you (as in the .xsd file in Solution Explorer while the OleDb method knows nothing about strong typed classes.

    So when the SELECT query (you showed) does not return what's in the strong typed classes it throws an exception.

    Yes I know this may possibly be confusing but I'm not trying too.

    Bottom line is that the TableAdapter method fields in the SELECT must match the strong typed class properties


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, October 25, 2017 4:18 PM
    Moderator
  • Hi srajmuneer,

    If you use TableAdapter to fill datagridview, you will see that there are some columns name like XXXXDataGridViewTextBoxColumn in the datagridview, like this:

    You can also see these columns name in datagridview in Form.Designer.vb, these are not same as the HeaderText in DataGridview. So you will get this error when you find some value by headerText.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Thursday, October 26, 2017 10:36 AM
    Thursday, October 26, 2017 8:13 AM
    Moderator
  • thank you very very much Cherry Bu for help , The problem is also described in your solution
    Thursday, October 26, 2017 10:41 AM