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

N

Neo Geshel

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.
***********************************************************************
 
C

Chris Priede

Hi,

Neo said:
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
,
[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
, ..." -- 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.
 
N

Neo Geshel

Chris said:
Neo said:
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
,
[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
, ..." -- 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.
***********************************************************************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top