Security :: ProviderUserKey - Using In A Select Statement?
Jan 31, 2011what I want to do is get the value of
Membership.GetUser().ProviderUserKey
and use it in a select statement so I can link it to the right table in the database..
what I want to do is get the value of
Membership.GetUser().ProviderUserKey
and use it in a select statement so I can link it to the right table in the database..
When I run the following debugging code it writes out credits:0
Dim MembershipUser As MembershipUser = Membership.GetUser()
Dim UID As String = MembershipUser.ProviderUserKey.ToString
SQL = "SELECT SUM(Credits) As Credits FROM Credits WHERE " & _
"DateDiff(m, [DateTime], GETDATE()) < 6 AND [UserID]=@UserID;"
cmd = New SqlCommand(SQL, Conn)
cmd.Parameters.Add(New SqlParameter("@UserID", UID))
DataReader = cmd.ExecuteReader()
If DataReader.HasRows Then
Do While DataReader.Read
[Code]....
If I log in to default membership provider, I don't get null on getReviewUserIdentity.ProviderUserKey.
However, if I log in non-default membership provider, I get null error although I'm authenticated.
Do I have to specify membership provider in order to use getReviewUserIdentity.ProviderUserKey??
Dim reviewUserID As String
If User.Identity.IsAuthenticated Then
Dim getReviewUserIdentity As MembershipUser = Membership.GetUser()
reviewUserID = getReviewUserIdentity.ProviderUserKey.ToString()
Else
reviewUserID = 0
End If
I have an application that has been running for about 1.5 years. Suddenly, I got a bug report that the support team are receiving an InvalidCastException in the User ManagerUnable to cast object of type 'System.Guid' to type 'System.String'. The line this appears to be happening on is:
string queryStringID = Session["EditID"].ToString();
Guid providerUserKey =
new
Guid(queryStringID)
MembershipUser user =
Membership.GetUser(providerUserKey);
<--- here
This is a rather strange error as the value of the queryStringID is in fact a Guid generated by the Membership.GetUser(UserName).ProviderUserKey on the previous page. It doesn't seem to make any sense at all. I'm using the built-in SqlMembershipProvider with no changes. It's as if it isn't picking up that it should be using the overloaded function Membership.GetUser(object providerUserKey)Anyone else ever seen anything like this? I wouldn't normally post here unless I was absolutely stuck but I can't seem to find any relevant information by Googleing this one. Also, it's just started doing this. There was never an issue before. Very strange
If I log in different membership provider, and go to page that contains following code, I get NullReferenceException error. User will be authenticated even if I loggin to different membership.
Is there any ways to prevent from getting error??
If User.Identity.IsAuthenticated Then
Dim UserIdentity As MembershipUser = Membership.Providers("CustMembershipProvider").GetUser(HttpContext.Current.User.Identity.Name, False)
Dim currentUserID As String = UserIdentity.ProviderUserKey.ToString()
i'm trying to to create a simple string array with data retrieved from a select statement(SELECT firstname FROM customers , for ex.)
View 6 RepliesHow would i make a select statement select the row with the nearest values? e.g.: I have 3 labels, labels1 2 and 3, with values of 1.2, 2 and 5.8 In my table i have 4 columns, first is the data im after, and the next 3 relate to the three labels. I want to select one row, where the values of labels match it the closest.......
View 8 Repliesi have two tables named
1.LookupPageInfo and (LookupPageInfoId,pathmessageID,pagemessageID)
2.Messages (MessageId,MessageText,ChannelID)
Now i need to write a query something like this........in the query i need to pass the pathmessageid and needs to get messagetext from Messages Table,i am not sure how i need to write the below query..can someone guide me how can i write a query......as below..
select LookupPageInfoId,
PathMessageID,
pagemessageID,
(select messagetext from Messages where MessageID=PathmessageId) as TEXT from LookupPageInfo
I have two dropdown list, which is 'names' and 'types' and it's being populated by a dataset. It contains an additional item "-- ALL --" to indicate that all items of a particular field are being shown. I have an SQL select statement to filter the records according to the selected item of the dropdowns. I used a select statement to bind the records to a datagrid with regards to the selected items.
SELECT * FROM table where name = ddlnameselecteditem AND type = ddltypeselecteditem
The problem now is when I select a name from the names dropdownlist and types dropdownlist has a selection of -- ALL --, there would be no return records because there's no such thing as '-- ALL --' record in column 'types' i'm querying. I need to display rows of the selected 'name' while still showing all the 'types'. How could I achieve this? I think I need to avoid the '-- ALL --' item from the dropdownlist.
I'm pretty new at ASP. I've got a sheet I'm trying to modify using an IF statement. I tried putting them in, in different ways, but it either shows up in the form or I get the options multiple times
[Code]....
i have a variable picked up elsewhere strArea, so I was trying to do
something like
[Code]....
I have tried putting the if's in different places, as well as case statement
but usually I end up with my drop down option list as
1
1
2
1
2
3
I'm trying to pull a list of clients that have both of two codes in the code table. Here is what I have tried and it does not return any rows. I know that there are clients that have both codes.
[Code]....
I am working on LINQ I m feeling difficult with getting the value from the LIST. Here is the following code
ccDataContext context = new ccDataContext();
I have the following select statement :
string Statement = "SELECT * FROM Car WHERE brand = Bmw;
how is it possble to display the result from the statement, because when i display the result exp: LblInfo.Text = Statement;
The result is : SELECT * FROM Car WHERE Brand = Bmw
I have records in the datatable which I have retreived from xml file.
Dim docDataSet As New DataSet
Dim docReader As New XmlDocument
Dim xnl As XmlNodeList
docReader.Load("UserProfile.xml")
xnl = docReader.SelectNodes("/Users/user")
For Each xn As XmlNode In xnl
Dim xr As New XmlNodeReader(xn)
docDataSet.ReadXml(xr)
Next xn
Dim Dm_table As DataTable = ds.tables(0)
Now what I want to do is execute a select query like below:
Select * from user where userid in (select ID from Dm_table)
Retreive the records from the User table based on the ID's in the datatable.
I thought this would be easy but cannot now find out of to do it. All I want to do is execute an sql query on a table and in addition to the table's columns I want to also select/output a field that is calculated within the query. The table has a column "Owner" and I want to compare this to the UserId to produce a bool column "mine". Effectively doing:Select *, (Owner=@UserId) as mine where.....however, this doesn't work so how can I calculate a column in the select statement?
View 3 RepliesI have to pull up a list of people by their branch number which could vary, and give a detailed report on there performance using a select queries. I have the select queries but how can i create a script to look similar to this one. Ive got the branch drop downlist already created just need to know how i can go about pulling all the users in this group and doing this select to all of them. someone told me I might need to use cursors to loop thru a select with every person in the list but im not sure how to go about that.
select fldusername from tbluser where fldio='o' and
flduserbranch=@branchid
is going to give me the names of the people i need to query. but how can i run a query on each of them seperate?
Here is the deal. I need to create a Stored Procedure that has 2 SELECT statements. Now in ASP.NET, I know that a DataSet can have multiple tables and the DataAdapter can do just that. I am stuck with a scenario where I need to get a value from the first SELECT statement which will later be used in the second SELECT statement. I am creating a SP that passes one parameter (@AnswerID). Which should give me 2 resultsets. See below SELECT statements.
[Code]....
So how do I get the QuestionID from the first SELECT statement?
Basically I am creating a Questionnaire that has Question Dependacies. So from the above SQL statements I would like to display the Question Title with it's relevant answer options but depending on the previous Answer selected hence the @AnswerID parameter.
The reason why I want to use 2 SELECT statements is because I don't want to have 2 roundtrips to th server. So in my code the DataAdapter should return 2 resultsets and fill the DataSet.
If there is any another solution that can prevent 2 roundtrips to the server, I would most definitely like to know how to do it.
Here's my SQL Statement
[Code]....
Unfortunately, I get the following error message:Message="The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified."
I have a select statement:
cmd = new SqlCommand("select lab_key from tblorderwhere", connection);
I would like to add a where statement that pass variable to the select statement. How I can do this?
Where lab_key =ChargeFine( that is my variable)
I am using join to get values from three tables. I want the first column to be Sl.No which autoincrements by 1.What should i write in the select for the first column.
View 4 RepliesIs it possible to sum to clolumns in one select statement?
[Code]....
[Code]....
ID sUM(aMOUNTpAID) sUM(aMOUNTdUE)
1234 506.64 4340.00
The actual rows look like this:
1234 10.00 5.00
1234 200.00 100.00
1234 130.00 130.00
1234 166.64 1000.00
totals 506.64 1235.00
i have the table like
TId DG rating DGMake DGCapacity
1 1 4 DG1 1X1
1 2 5 DG2 2X2
1 3 3 DG3 3X3
i need the output like this.
TId DG1 DG2 DG3 DG1Rating DG2Rating DG3Rating DG1Make DG2Make DG3Make DG1Capacity DG2Capaciy DG3Capacity
1 1 2 3 4 5 3 DG1 DG2 DG3 1X1 2X2 3X3
this might be an easy one, but I just can't get it.I am creating a page which will query a table with many columns and most items are not unique. I need to be able to get a list of records that match as many of the (up to 4) search criteria as possible.Example:am user searching for the following items, I enter at least one and up to 4 of the items below in a text box:Name, age, gender, weight (user may or may not fill in all of them).If he just enters "F" for gender, then he will get a list of thousands of females with their name, age, gender and weight.However if he enters "F" for gender and "300" for weight, he will get a much smaller list of returned records.I need to be able to create a sql statement that can perform that search with that functionality.
View 6 Replieshow can i use Distinct in my sql statement like that
SELECT
Distinct * from my_table ?? ? ? ?? ? ? ?
I have a select statement where I want to get some data. The problem is that I am not geting the right answer. This is what I am trying to do:
SELECT * FROM se_cs_test WHERE
Status = 1
OR Status = 2
AND NumberOfContacts = 1[code]...