473,466 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

datatable problem

38 New Member
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..?
Mar 4 '09 #1
8 1012
alamodgal
38 New Member
please send code what u actually doing?
Mar 4 '09 #2
kunal pawar
297 Contributor
I think, Price column should be text. And check new price in string if it exist thn do not update column otherwise update column
Mar 4 '09 #3
avinash sh
38 New Member
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?
Mar 4 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
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.
Mar 4 '09 #5
avinash sh
38 New Member
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.datasource=datatable;
grid1.databind();
it gives me output of simple form like table1... but i want output like table 2.. what to do for that....?
Mar 4 '09 #6
tlhintoq
3,525 Recognized Expert Specialist
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.
Mar 4 '09 #7
avinash sh
38 New Member
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
Mar 5 '09 #8
bhupinder
32 New Member
@avinash sh
Hiiiiiiii avinash
I dont know, what are you implement in your code.
Expand|Select|Wrap|Line Numbers
  1.  Sub load_data()
  2.         Dim query As String
  3.         query = "Select id from tbl_price group by id"
  4.         Dim ds As New DataSet
  5.         Dim adp As New SqlDataAdapter(query, con)
  6.         adp.Fill(ds)
  7.         gvdata.DataSource = ds
  8.         gvdata.DataBind()
  9.  
  10.     End Sub
  11.  
  12.     Protected Sub gvdata_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvdata.RowDataBound
  13.         If e.Row.RowType = DataControlRowType.DataRow Then
  14.             Dim query As String
  15.             Dim count As Integer
  16.             Dim id, price As String
  17.             query = "select price from tbl_price where id = " & gvdata.DataKeys(e.Row.RowIndex).Value
  18.  
  19.             Dim ds As New DataSet
  20.             Dim adp As New SqlDataAdapter(query, con)
  21.             adp.Fill(ds)
  22.  
  23.  
  24.             For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
  25.  
  26.                 price &= ds.Tables(0).Rows(i)("price") & ","
  27.             Next
  28.             Dim lbl As Label = CType(e.Row.Cells(1).FindControl("lblPrice"), Label)
  29.             lbl.Text = price.Substring(0, price.Length - 1)
  30.  
  31.         End If
  32.     End Sub
  33.  
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
Mar 5 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
4
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
5
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.