Splitting Data in "TEXT" datatype

  • Firstly Hi everyone,

    Just joined the site, seems to be alot of information on here, just haven't figured out how to search yet!!

    my problem is im connecting to a database using asp.net, from a .aspx file for a web page.

    with in the code i have a function to select my information from a database.

    the columns are;

    FeedbackID - Unique ID for a feedback post,

    UserID - ID of the user who made the post,

    FeedBackText - a string of text saved as a text datatype.

    the data is pulled out using SQL so;

    SELECT [FeedBackID], [UserID], [FeedBackText] FROM [UserFeedBack]

    i want to pull out the infomation for each of these, and then separate the long string of text contained by the FeedBackText, and present it as a separate items on a table.

    so for example it would look something like this;

    _____________________________________

    |UserID = 1__________|FeedBackID = 1___|

    ------------------------------------------

    |FeedBackText:______|________________|

    ------------------------------------------

    |How are you?_______|___related answer_|

    |how was your day?__|___related answer _|

    |have you eaten?____|___related answer__|

    -------------------------------------------

    any help would be appreciated guys,

    Thanks Very much,

    Jon

  • ok, the way to do this is to use unions, casts and hidden columns

    for example

    select feedbacktext

    from (

    select feedbackid, 0 as orderx, cast('UserId = '+

    cast(user_id as varchar(10))+'FeedbackId='+

    cast(feedbackid as varchar(10)) as varchar(1000)) as feedbacktext

    from userfeedback

    union

    select feedbackid, 1 as orderx, FeedBackText

    from UserFeedBack) x

    order by FeedbackId, Orderx

    the first subquery is building a text line of the data you want that is a combination of the text, but it also needs the feedbackid and the orderx columns to sort on after the union. the second query provides the text, then you just return the select from the 2 queries via a union and order.

    I know it seems hard but once you grasp the concept you can use this technique to force ordering within ordering to create any ordering you want.

    Paul Ross

  • Assuming that your text field contains some sort of delimiter it should be possible to seperate the text into seperate lines either in SQL or in your .ASPX page.

    If you want to do it in SQL search this site for "split string", there are a couple of table functions floating around that take a string/text and return a table with a row for every time the delimiter is found in the string/text.

    You could do the same thing in your .ASPX page with string.split()... which will break your text into an array for further processing.

    Joe

  • Thanks for your replies guys,

    still cant seem to make head or tail of this though, i have used the split() function before with in a normal asp page, but cant seem to use it in a .aspx page... :unsure:

    the code i trying to modify is

    <!--

    asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" "

    SelectCommand="SELECT [feedBackID], [feedBackText], [userID] FROM [userFeedback]">

    /asp:SqlDataSource>

    asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="feedBackID"

    DataSourceID="SqlDataSource1">

    Columns>

    asp:BoundField DataField="feedBackID" HeaderText="feedBackID" InsertVisible="False"

    ReadOnly="True" SortExpression="feedBackID" />

    asp:BoundField DataField="feedBackText" HeaderText="feedBackText" SortExpression="feedBackText" />

    asp:BoundField DataField="userID" HeaderText="userID" SortExpression="userID" />

    /Columns>

    /asp:GridView>

    ->

    and that currently loads all of the string from the database into each

    column field.

    i guess the operation for splitting the FeedBackText String should happen before they are called into the asp:grid. but i cant seem to use Dim as i would normally in asp to then use the Split() fucntion.

    sorry to be a nuisiance. just cant seem to implement the solutions you guys provided.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply