dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] vs 2017 dataset retrieves only 1 filed from the database why?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Resolved [RESOLVED] vs 2017 dataset retrieves only 1 filed from the database why?

    hey
    i am trying to print data according to the sql query using dataset
    problem is that it print only the first column why?
    what am i missing?
    this is my code
    Code:
    table name -payments
    fields - PaymentMethod,Amount,CreditCardNumber
    Code:
                Dim objRpt As New CreditCardReport  'Crystal report 
                Dim ds As New DataSet
                Dim SQL As String = "Select Count(Payments.ID) As CountOfID ,Payments.CreditCardName,
                Sum(Payments.Amount) As SumOfAmount
                From Payments Where PaymentMethod=@PaymentMethod
                AND DatePayRishum>=@DatePay
                AND DatePayRishum<=@DatePay1
                Group By Payments.CreditCardName"
    
                Dim da As New SqlDataAdapter(SQL, Cn)
                Cn.Open()
                da.SelectCommand.Parameters.AddWithValue("@PaymentMethod", "CreditCard")
                da.SelectCommand.Parameters.AddWithValue("@DatePay", Format(DtStart.Value, "MM\/dd\/yyyy 00:01"))
                da.SelectCommand.Parameters.AddWithValue("@DatePay1", Format(DtEnd.Value, "MM\/dd\/yyyy 23:59"))
                da.Fill(ds, "payments")
                Cn.Close()
                
                'to print --------------------------------------
                objRpt.SetDataSource(ds.Tables(0))
                objRpt.PrintToPrinter(0, True, 0, 0)
                objRpt.Dispose()
    I need to print also amount but it dosnt print.
    tnx for any help
    salsa

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,728

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    Firstly, don't create a DataSet if all you need is a DataTable. Just create a DataTable.

    As for the issue, the tile says that your code is only retrieving one column but I'd wager that that is simply not true. Have you actually examined the DataTable to see what it contains? I'd wager not. I'm guessing that the DataTable contains exactly what it should and the issue is with the report.

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    how can i see what is accutaly the datatable is retrieving ?

  4. #4
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,986

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    do a row count on the Datatable
    does it only return 1 ?
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    Quote Originally Posted by ChrisE View Post
    do a row count on the Datatable
    does it only return 1 ?
    like this?
    Code:
                Dim collection As DataTableCollection = ds.Tables
                For i As Integer = 0 To collection.Count - 1
                    Dim table As DataTable = collection(i)
                    MessageBox.Show(i)
                Next
    shows me 0

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,728

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    Quote Originally Posted by salsa31 View Post
    like this?
    Code:
                Dim collection As DataTableCollection = ds.Tables
                For i As Integer = 0 To collection.Count - 1
                    Dim table As DataTable = collection(i)
                    MessageBox.Show(i)
                Next
    shows me 0
    Um, what could possibly be the use of displaying that loop counter? I always feel like I'm in the twilight zone in your threads. If you want to know how many columns are in the DataTable then look at the Count property of its Columns collection. Why are you even writing code to do this? Set a breakpoint and use the debugger.

  7. #7
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,986

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    Quote Originally Posted by salsa31 View Post
    like this?
    Code:
                Dim collection As DataTableCollection = ds.Tables
                For i As Integer = 0 To collection.Count - 1
                    Dim table As DataTable = collection(i)
                    MessageBox.Show(i)
                Next
    shows me 0
    I just saw you are using a Dataset, the Values are all there if you Filled that Dataset correctly
    Code:
    '..your code to fill, then do the Count
            MsgBox(myDataSet.Tables.Count()) 
            MsgBox(myDataSet.Tables(0).Rows.Count())
            MsgBox(myDataSet.Tables(0).Columns.Count())
    not sure what you want with the collection?
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    jmc you are right
    the problem was in the report
    tnx

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: vs 2017 dataset retrieves only 1 filed from the database why?

    tnx chris for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width