datatable problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • avinash sh
    New Member
    • Feb 2009
    • 38

    datatable problem

    i have a table like that:-

    coll'n_id price
    ----------- --------
    1 ---- 500
    1 ---- 600
    2 ---- 300
    2 ---- 400
    2 ---- 800
    3 ---- 200
    4 ---- 200

    and i want the output like that:-

    coll'nn_id price
    ----------- --------
    1 ------ 500,600
    2 ---- 300,400,800
    3 ---- 200
    please suggest me how can achieve this output?it means i want for same collection_id different price come in same row sepreated by comma(,) and if the price is same for same collection_id then single price would display ,not duplicate price in same column..... plz help me..?
  • alamodgal
    New Member
    • Dec 2008
    • 38

    #2
    please send code what u actually doing?

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      I think, Price column should be text. And check new price in string if it exist thn do not update column otherwise update column

      Comment

      • avinash sh
        New Member
        • Feb 2009
        • 38

        #4
        ya price column is the type of string but i am not able to compare with privious row value.... and how to after comparision append to price column if
        the id is same? plz send me sample code for that?

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Avinash_Sh:
          You've asked for 'sample' code of how to fix your problem, but couldn't be bothered with supplying the code that you are currently using when asked by Alamodgal.

          You've said that you not able to compare the value with the previous row. Why not? Its your code. You can do whatever you like with it. If you can't *currently* compare row 2 to row 1 before displaying row 1, then change what you've written so you can.

          Since you are unwilling to provide the code you've done so far the people here have nothing more to go on, if you won't help them to help you.

          Comment

          • avinash sh
            New Member
            • Feb 2009
            • 38

            #6
            actually i got the result set from my stored procedure...and assigned in a dataset and added to datatable which i explained you in table one.....and now i have to display on gridview to this datatable in format of second table....
            code is like that..

            i got datatable from sp
            then i am assigning datasource of gird like that
            grid1.datasourc e=datatable;
            grid1.databind( );
            it gives me output of simple form like table1... but i want output like table 2.. what to do for that....?

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              I believe that to do what you want to accomplish you are not going to be able to go the 'easy' route of just binding data to controls. As Alamodgal and Kunal suggested you are going to have to receive the data, process the data into formated strings that look the way you want them to, then display the formatted string.

              Comment

              • avinash sh
                New Member
                • Feb 2009
                • 38

                #8
                actually i am a beginer.. so plz tell me how to compare the existing value with current value of datatable and update the second column by concatinate new value previous one to previous one...? send small code or link for that..? plzzzzzz

                Comment

                • bhupinder
                  New Member
                  • Feb 2009
                  • 32

                  #9
                  please use code tags

                  Originally posted by avinash sh
                  actually i am a beginer.. so plz tell me how to compare the existing value with current value of datatable and update the second column by concatinate new value previous one to previous one...? send small code or link for that..? plzzzzzz
                  Hiiiiiiii avinash
                  I dont know, what are you implement in your code.
                  Code:
                   Sub load_data()
                          Dim query As String
                          query = "Select id from tbl_price group by id"
                          Dim ds As New DataSet
                          Dim adp As New SqlDataAdapter(query, con)
                          adp.Fill(ds)
                          gvdata.DataSource = ds
                          gvdata.DataBind()
                  
                      End Sub
                  
                      Protected Sub gvdata_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvdata.RowDataBound
                          If e.Row.RowType = DataControlRowType.DataRow Then
                              Dim query As String
                              Dim count As Integer
                              Dim id, price As String
                              query = "select price from tbl_price where id = " & gvdata.DataKeys(e.Row.RowIndex).Value
                  
                              Dim ds As New DataSet
                              Dim adp As New SqlDataAdapter(query, con)
                              adp.Fill(ds)
                  
                  
                              For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                  
                                  price &= ds.Tables(0).Rows(i)("price") & ","
                              Next
                              Dim lbl As Label = CType(e.Row.Cells(1).FindControl("lblPrice"), Label)
                              lbl.Text = price.Substring(0, price.Length - 1)
                  
                          End If
                      End Sub
                  I used gridview not a datatable. If you find any problem implement in this code. So reply me. Use this code in gridview. it definate work
                  Last edited by tlhintoq; Mar 5 '09, 03:33 PM. Reason: [CODE] ...your code here... [/CODE] tags added

                  Comment

                  Working...