Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I am have one noob question, I searched all the google for the answer but didnt find anything useful. I have this command
var name = db.Query("SELECT User FROM UserProfile WHERE UserId= "+row.FromUserId) );
I want to variable name contain a name of person with id, but query returns some kind of collection and I cant figure out what to do next. Thanks
Posted
Comments
[no name] 2-Aug-13 11:53am    
Okay.... what exactly is that you want to do next?
wirec aaht 2-Aug-13 12:05pm    
I want to use name of user in chat, but I only have ID. Like in WebSecurity is function GetUserId() I want it reverse. I have Id but I want name of user. :)
woopsydoozy 2-Aug-13 12:28pm    
what kind of DB are you hitting (SQLServer, Oracle, other?), and what kind of object are you using to query it (what type is your db variable, and what type does Query return)?
ridoy 2-Aug-13 12:48pm    
not clear at all.
wirec aaht 2-Aug-13 13:09pm    
I am using SQLServer I will paste here all page.


@{Layout="Layout.cshtml";
var db = Database.Open("test");
var query= "SELECT * FROM Messages WHERE FromUserID='"+WebSecurity.CurrentUserId+"' OR ToUserID='"+WebSecurity.CurrentUserId+"';";

}

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Správy</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>
<style>
#accordion-resizer {
padding: 10px;
width: 750px;
height: 350px;
}
</style>
<script>
$(function() {
$( "#accordion" ).accordion({
heightStyle: "fill"


});
});
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
/* $(function() {
$( "#accordion-resizer" ).resizable({
minHeight: 140,
minWidth: 200,
resize: function() {
$( "#accordion" ).accordion( "refresh" );
}
});
});*/
</script>
</head>
<body>
<div id="accordion-resizer" class="ui-widget-content">
<div id="accordion">
@foreach(var row in db.Query(query))
{
var name = db.Query("SELECT User FROM UserProfile WHERE UserId= "+row.FromUserId) );


@name


<div>
<p>
@row.Message v čase @row.CreateDate
</p>
</div>
}

</div>
</div>
</body>
</html>

1 solution

I have solved it if I use var name = db.QuerySingle("SELECT * FROM UserProfile WHERE UserId= @0",row.FromUserID); then it is name.User :) Thanks all
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900