Adding external data into database data before it is sent to Control(Repeater, Datagrid, etc.)

Discussion in 'ASP .Net' started by Neo Geshel, Nov 13, 2005.

  1. Neo Geshel

    Neo Geshel Guest

    I am looking to add additional data into a "stream" that has been
    extracted from a database, but before it is sent to a control (Repeater,
    in this case).

    I have found ZERO (0) articles about this on the Internet. Anyone care
    to point me in the right direction? I am not looking for code that
    rivals Gray's Anatomy in complexity, just something that can add a
    static variable in a line or two of code (at the most).

    My script so far looks like this:

    Dim myConn as New
    OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
    Dim myCmd_img as New OleDbCommand("SELECT [ID], [Comment] FROM [tbl"
    & strSlave & "] WHERE [" & strMaster & "ID] = " & intMaster & " AND [ID]
    = " & intSlave, myConn)
    myConn.Open()
    Img.DataSource = myCmd_img.ExecuteReader(CommandBehavior.CloseConnection)
    Img.DataBind()
    myConn.Close()

    What I want to do is add the table name, contained within the string
    strSlave, into the data extracted from the table. I want to assign it a
    variable of "Table". That way, I can call it by its variable in the
    Repeater.

    I do not want to add the name of the table TO the database, I just want
    to add it to the stream of data extracted FROM the database. Ideally, it
    would be something as simple as this:

    Img.Items.Insert(0, new Item(strSlave, "Table"))

    But this doesn't work.

    TIA,
    ...Geshel
    --
    ***********************************************************************
    * My reply-to is an automatically monitored spam honeypot. Do not use *
    * it unless you want to be blacklisted by SpamCop. Please reply to my *
    * first name at my last name dot org. *
    ***********************************************************************
    “Anyone who believes in Intelligent Design (“creationismâ€) is just as
    ignorant and ill-educated as someone who believes that the world is
    flat, that the Sun circles the Earth or that there really is a tooth
    fairy. Darwinism has an overwhelming foundation of evidence that can be
    tested and reproduced. Intelligent Design, on the other hand, has no
    evidence at all; not one single shred of testable proof. As such,
    Intelligent Design is Religious Mythology, and has no right whatsoever
    to be in our Science classrooms.†- 99.99+% of Scientists
    ***********************************************************************
    Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
    obsessed with sex as the average man.†Unfortunately, since true
    nymphomaniacs are so rare, this means that it takes an extraordinary
    woman to keep up with an ordinary man.
    ***********************************************************************
    Neo Geshel, Nov 13, 2005
    #1
    1. Advertising

  2. Neo Geshel

    Chris Priede Guest

    Re: Adding external data into database data before it is sent to Control (Repeater, Datagrid, etc.)

    Hi,

    Neo Geshel wrote:
    > Dim myCmd_img as New OleDbCommand("SELECT [ID], [Comment] FROM
    > [tbl" & strSlave & "] WHERE [" & strMaster & "ID] = " & intMaster & "
    > AND [ID] = " & intSlave, myConn)


    > I do not want to add the name of the table TO the database, I just want
    > to add it to the stream of data extracted FROM the database.


    You can achieve exactly what you want by adding to your SQL query. You can
    SELECT not just table columns, but also literal values: nothing stops you
    from doing the following:

    Dim myCmd_img as New OleDbCommand("SELECT 'tbl" & strSlave & "' AS [Table],
    [ID], [Comment] FROM
    [tbl" & strSlave & "] WHERE [" & strMaster & "ID] = " & intMaster & "
    AND [ID] = " & intSlave, myConn)

    I hope I did the VB concatenation right (I am not a VB programmer). The
    SQL we are going for is: "SELECT 'tblWhatever' AS [Table], ..." -- note the
    single quotes around the literal value. This will return an additional
    column named "Table" and containing the given value, for each returned row.

    --
    Chris Priede

    P.S. I hate concatenated queries -- consider using parameters. :)
    Chris Priede, Nov 13, 2005
    #2
    1. Advertising

  3. Neo Geshel

    Neo Geshel Guest

    Re: Adding external data into database data before it is sent toControl (Repeater, Datagrid, etc.)

    Chris Priede wrote:
    > Neo Geshel wrote:
    >> Dim myCmd_img as New OleDbCommand("SELECT [ID], [Comment] FROM
    >>[tbl" & strSlave & "] WHERE [" & strMaster & "ID] = " & intMaster & "
    >>AND [ID] = " & intSlave, myConn)

    >
    >>I do not want to add the name of the table TO the database, I just want
    >>to add it to the stream of data extracted FROM the database.

    >
    > You can achieve exactly what you want by adding to your SQL query. Youcan
    > SELECT not just table columns, but also literal values: nothing stops you
    > from doing the following:
    >
    > Dim myCmd_img as New OleDbCommand("SELECT 'tbl" & strSlave & "' AS [Table],
    > [ID], [Comment] FROM
    > [tbl" & strSlave & "] WHERE [" & strMaster & "ID] = " & intMaster & "
    > AND [ID] = " & intSlave, myConn)
    >
    > I hope I did the VB concatenation right (I am not a VB programmer). The
    > SQL we are going for is: "SELECT 'tblWhatever' AS [Table], ..." -- note the
    > single quotes around the literal value. This will return an additional
    > column named "Table" and containing the given value, for each returned row.
    >

    Actually, this works beautifully, I just had to add my values after any
    SQL SELECT operations (such as “SELECT TOP 1â€) and beforethe FROM.
    Otherwise Access chokes on the statement.

    Thanks.
    ...Geshel
    --
    ***********************************************************************
    * My reply-to is an automatically monitored spam honeypot. Do not use *
    * it unless you want to be blacklisted by SpamCop. Please reply to my *
    * first name at my last name dot org. *
    ***********************************************************************
    “Anyone who believes in Intelligent Design (“creationismâ€) is just as
    ignorant and ill-educated as someone who believes that the world is
    flat, that the Sun circles the Earth or that there really is a tooth
    fairy. Darwinism has an overwhelming foundation of evidence that can be
    tested and reproduced. Intelligent Design, on the other hand, has no
    evidence at all; not one single shred of testable proof. As such,
    Intelligent Design is Religious Mythology, and has no right whatsoever
    to be in our Science classrooms.†- 99.99+% of Scientists
    ***********************************************************************
    Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
    obsessed with sex as the average man.†Unfortunately, since true
    nymphomaniacs are so rare, this means that it takes an extraordinary
    woman to keep up with an ordinary man.
    ***********************************************************************
    Neo Geshel, Nov 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Vecchi
    Replies:
    4
    Views:
    493
    Jacob Yang [MSFT]
    Oct 31, 2003
  2. Rahul Agarwal
    Replies:
    3
    Views:
    440
    Jim Cheshire [MSFT]
    Aug 6, 2004
  3. =?Utf-8?B?cnBhbGU=?=

    httphandler to intercept pages before sent to user

    =?Utf-8?B?cnBhbGU=?=, Dec 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    572
    Steven Cheng[MSFT]
    Dec 16, 2004
  4. Brian Simmons
    Replies:
    2
    Views:
    678
    Brian Simmons
    Jul 19, 2007
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    383
    Fredrik Lundh
    Aug 13, 2008
Loading...

Share This Page