Click to See Complete Forum and Search --> : Database values as variables


camdaman
04-11-2005, 09:16 PM
I am using a database to get my data and I use <%#Container.DataItem("FIELD")%> to get any of my data from the Repeater contriol

What I am trying to do is get the value and either pass is a a variable (cant or not sure how to store as a variable) or just compare to a certain string

Basically I have Multiple Choice trivia and regular trivia and I would have a QuestionType field and would like to compare

if <%#Container.DataItem("Type")%> = "M"
<table border="0" cellspacing="2" cellpadding="2">
<td>A - <%# Container.DataItem("A")%></td></tr>
<tr><td>B - <%# Container.DataItem("B")%></td></tr>
<tr><td>C - <%# Container.DataItem("C")%></td></tr>
<tr><td>D -<%# Container.DataItem("D")%></td></tr>
</table>
<%end if%>

but the if statement wont execute so how do you get the value from the database using variables or another method

Thanks in advanced

webgovernor
04-11-2005, 11:14 PM
Is that ASP?
(I don't know any .NET/ASP stuff....)

Are you using a mySQL database?

I could tell you the php method...

I usually get info from the mySql DB in the form of an
associative array:

Php <?php
$dbConnect = mysql_connect("localhost", $dbUser, $dbPass) or die
('I cannot connect to the database because: ' . mysql_error());

mysql_select_db($db);

$query = "SELECT * FROM `$mainTable` WHERE username='$user' AND password = '$pass'";
$resultSet = mysql_query($query);
$array = mysql_fetch_assoc($resultSet);

$name = $array['name'];
$email = $array['email'];
?>

I don't know if that's what you're looking for, or what the asp code is for that.

But since I'm new here, I've been trying to help as much as possible.

Good luck!

camdaman
04-12-2005, 11:04 AM
Its ASP.NET code with Access database

CardboardHammer
04-13-2005, 12:34 PM
if <%#Container.DataItem("Type")%> = "M"

You're going into code late and leaving early.

Try this instead:
<%# if Container.DataItem("Type") = "M" %>

camdaman
04-13-2005, 09:47 PM
I tried <%# if Container.DataItem("Type") = "M" %>
I tried
<%# if Container.DataItem("Type") = "M" then%>
THIS IS A TEST
<%END IF%>
and error message is expression expected