Hi, any suggestions on why my label doesn't show the current user.identity.name when used in a detailsview (header-field or insert-field), when it works just fine placed directly on my page ?
Please help ! (I want to bind myLabelX.Text to a db-table, but it contains no value..)
codebehind : 1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12
13 public partial class Test_2 : System.Web.UI.Page
14 {
15
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 if ((!IsPostBack)) myLabelX.Text = User.Identity.Name;
19 }
20
21 }
Here is my code. Basically what I am doing is selecting from the database based on the current user. The ReaderResults.Text label is not showing the info pulled from the database, and the ReaderError.Text label is not showing an error. I also tried putting the ReaderResults.Text label inside the loop and that didnt work. Any suggestions? 'Database ConnectionDim con As New SqlConnection("Data Source = .SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|ASPNETDB.mdf;user instance=true")Dim currentUserID currentUserID = Context.User.Identity.Name.ToString() Label1.Text = currentUserID Dim selectSQL As String selectSQL = "SELECT companyKey FROM Company WHERE UserID = ('" + currentUserID + "')"Dim cmd2 As New SqlCommand(selectSQL, con) Dim reader As SqlDataReaderDim CompanyKey Try con.Open() reader = cmd2.ExecuteReader()Do While reader.Read() CompanyKey = reader("CompanyKey").ToString() Loop reader.Close()Catch err As Exception ReaderError.Text = "Error selecting record." ReaderError.Text &= err.Message ReaderResults.Text = CompanyKey Finally con.Close() End Try
The ReaderResults.Text is not returning a value. I am not sure what is going on because the table and all columns are full, Label1.Text shows the current username of the user loggedon, and no error is showing up in ReaderError.Text. Anyone have any ideas? Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Database ConnectionDim con As New SqlConnection("Data Source = .SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|ASPNETDB.mdf;user instance=true") 'Job1 InfoDim currentUserID currentUserID = Context.User.Identity.Name.ToString() Label1.Text = currentUserID Dim selectSQL1 As String selectSQL1 = "SELECT companyKey FROM Company WHERE UserID = ('" + currentUserID + "')"Dim cmd1 As New SqlCommand(selectSQL1, con) Dim reader As SqlDataReaderDim CompanyKey 'Job1 Select Try con.Open() reader = cmd1.ExecuteReader()Do While reader.Read() CompanyKey = reader("CompanyKey").ToString() Loop reader.Close()Catch err As Exception ReaderError.Text = "Error selecting record." ReaderError.Text &= err.Message ReaderResults.Text = CompanyKey Finally con.Close() End Try
I need help. The security principal is the correct DomainUser, but the error message says I am not authenticated. So here is my error Message: Login failed for user 'NT AUTHORITYANONYMOUS LOGON'. Me.User.Identity.Name=CompanyDomainRyan; System.Security.Principal.WindowsIdentity.GetCurrent=CompanyDomainRyan; HttpContext.Current.User.Identity.Name=CompanyRyan Generated by: Dim secPrinc As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent Me.lblError.Text = ex.Message & vbCrLf & vbCrLf & "Me.User.Identity.Name=" & Me.User.Identity.Name & "; System.Security.Principal.WindowsIdentity.GetCurrent=" & secPrinc.Name & "; HttpContext.Current.User.Identity.Name=" & HttpContext.Current.User.Identity.Name Here is the Connection String: Private ConnString As String = "Server=10.144.162.111;Database=DNS;Trusted_Connection=True"
IIS has 4 websites hosted on it. The parent level allows anonymous with windows auth off, but the website level has anonymous off with widnows auth and digest. In IIS, is there a problem with having the parent level anonymous and website level windows auth?
Several apps connecting to a SQL 2008 server show the users having a hostname of "Various" when doing an sp_who2 or looking at relevant DMVs.
I joined dm_exec_sessions to dm_exec_connections and was able to get the IP addresses and they resolve back to real clients. So why they'e not displayed and I see "Various" instead?
Now, I have a report where whoever is logged in will only see data for themselves and those below them, so John Smith would see everyone including himself, but Lisa Andres would only see herself and Bob Thompson. James Jones would be able to see everyone except John Smith.
How do I go about implementing this code, for example in an asp.net page where one of the user's logs on to view the report. Currently, there is a T-SQL function that creates a user heirarchy table, but it is very slow and I am curious if SSRS 2005 has any new capabilities in handling this.
HiI have a Jobs Table: Job_ID,User_ID,Job_Info,...Job_ID is the Primary Key.I want to add [Job_ID_PerUser] so I wiil get:Job_ID Job_ID_PerUser User_ID1 1 A2 1 B3 1 C4 2 A5 3 A6 2 CThanks
Hi,I have an on screen control to select data from a table. Here are the parameters for the select: <asp:Parameter DefaultValue="bezlan" Name="recievername" /> <asp:Parameter DefaultValue="bezlan" Name="recieversname" />this works perfectly if I sign in as bezlan <asp:Parameter DefaultValue="User.Identity.Name" Name="recievername" /> <asp:Parameter DefaultValue="User.Identity.Name" Name="recieversname" /> this doesnt pick up any data at all if I sign in as bezlan.Why is this? Is there a special bit of code I need for parameters?Thanks,Jon
Hello everyone, In SQL Query I need to update a field to my ASP.NET app which has a variable User.Identity.Name() where it contains the Form Authentication of current logon user, SQL has the suser_name() function but this is not what I needed because it returns the user accessing the Database. UPDATE [tblData] SET [UserUpdated] = User.Identity.Name() <= this failed because SQL doesn't recordnize the User.Identity.Name() function. Is there any method I can use to achieve this? Thanks in advance.
is there a way that I can use the sqldatasource with a form view where my sqldatasource select statement is like this select * from tblUsers where vcUserName=@vcUserName <selectparameters> <asp:Parameter Name="user.identity.name" Type="String /> </selectParameters>
Hiy all, I have used the code below to capture the current logged in user into my LoginID Filed in my SQL DB. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SqlDataSource1.InsertParameters("LoginID").DefaultValue = Page.User.Identity.Name End Sub Now that I have this in my DB I want to create a Gridview that will filter by this LoginID. So I want to filter all records where LoginID = the currenlty logged in user ie: filter using Page.User.Identity.Name So in my SQL code I have WHERE loginID = @Currentuser. VWD now wants me to define a parameter for this Varaibale @Currentuser... So I want to set this to Page.User.Identity.Name. My Problem is that in the datasource define parameter area I'm not sure what to define this as. ie: is Page.User.Identity.Name a cookie , control , Query String , session ? can someone point me in the right direction to what syntax to use? Ray..
I use forms authentication with my Report manager. The problem is that I can't display the same information to all the users into the report. For example, in my report, i have one dataset that give me a list of all the store of a compagny. And i have to display only the store onto the user is working. If the user is a boss, he can see the information of all the stores. So i have to know in my report what is the login he uses in the form authetication and i don't know how to do.
Hi,How do I get hold of the HttpContext.Current.User.Identity.Name from within an sqldatasource? I want to create a WHERE clause that says WHERE UserName = @UserName and the @UserName parameter be filled with the current user name. I would be able to do this in code, but I don't know how to get at this information from within a datasource. At a guess I tried to use the Cookie option from the drop down list, and use the name of the FormsAuthentication Cookie, but this didn't work. Is there a way I can do this? If so how? I don't want to resort to using a hidden field or anything like that if I can help it. Many thanks, Steve
Hello everyone, I have a view, NAS_vPosition that has a coloumn vLogin_Acting and I want to use the user.identity.name to select the row from this table that matches. So far i have tried: SelectCommand = "Select * FROM NAS_vPosition WHERE vLogin_Acting = ' <%=User.Identity.Name %> ' " with no success. Any help is appreciated
Hi,I am using detailsview to update my database and got a question regarding datetime format. Here is part of my code: <asp:TemplateField HeaderText="Project Deadline"> <EditItemTemplate> <asp:TextBox ID="txtDeadline_edit" runat="server" Text='<%# Bind("pro_app_deadline") %>'></asp:TextBox> <asp:CompareValidator ID="txtDeadlineedit_validator" runat="server" ErrorMessage="Not a valid date format" ControlToValidate="txtDeadline_edit" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator> </EditItemTemplate> <ItemTemplate><asp:Label ID="txtDeadline" runat="server" Text='<%# Eval("pro_app_deadline") %>'></asp:Label> </ItemTemplate></asp:TemplateField> Since the format of my parameter 'pro_app_deadline' is datetime, it get stored as YYYY-MM-DD hh:mm:ss in datebase. If I want to validate user's input like above way, it always fails since hh:mm:ss append to YYYY-MM-DD. My question is, is there some way I can avoid hh:mm:ss? Thanks a lot!
Can someone please tell me what I am doing wrong... I have a simple webform that has contains a GridView and a DetailsView. Once the GridView is populated the user simply selects a record from the list. The DetailsView is them populated with all of the data from the selected record. The DetailsView is bound to a SQL DataSource/CustomerData. I have made sure that the DV control has the Edit/Update Command listed. The user can click the Edit button and successfully edit the fields but when the user clicks the "Update" button I am getting the following message. Updating is not supported by data source 'CustomerData' unless UpdateCommand is specified Why isnt the control handling the Update. Many Thanks!!!! T
I am having issues getting this to work. I have the user login to a page to put in a request for vacation. When they login, I have a label that isn't visible that is equal to their User.Identity.Name. I select the user from the employee table where the username = the label User Identity Name and pull in the emp_id which is the primary key that identifies the user. I need to insert the request into the request table with the emp_id from the select statement, without showing the em_id on the screen. I tried using a hidden field and assigning the emp_id as the value, but it isn't working. Not sure if this is the best way to do this. Really new to ASP.NET 2.0 so I really appreciate any help. Thank you!
I am new to MS SQL SERVER 2005. My web application using SQL Server 2005 as back end database to store all the information. I am using connection pooling to get connection form db. But my fron end user( user who logged in into webapplication) lost his identity b'coz for database user is application server. Now I wanna to track front end user in db.
In oracle I can do it by using CLIENT_IDENTIFIER. But in sql server I don't know how to do it.
in oracle i can do it as below public void setIdentity(Connection conn, String identity) { PreparedStatement ps; try { ps = conn.prepareCall("begin dbms_session.set_identifier(?); end;"); ps.setString(1, identity); ps.execute(); ps.close(); } catch (SQLException e) { // Handle the exception } } <!--[if !supportLineBreakNewLine]--> once the transaction is complete, the application should reset the identity as follows:
public void clearIdentity(Connection conn) { PreparedStatement ps; try { ps = conn.prepareCall("begin dbms_session.clear_identifier(); end;"); ps.execute(); ps.close(); } catch (SQLException e) { // Handle the exception } } <!--[if !supportLineBreakNewLine]--> Please guide me for same.
Hi everybody,I have a little Problem with an update and Detailsview.I have 2 table (tblUser - uid,uName,rId) and (tblRole - rId, rDescription) In my update I don't want to use the roles id, I want to use the roles Description.Via sql I do a update the role to Admin like that UPDATE tblUser SET rId = (SELECT rId FROM dbo.tblRoles WHERE (rDescription = 'Admin')) But I don't get it to work for the detailsview update
i get Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857354 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734966 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 ...i am using the Edit feature of the detailsview, seems like the datatype is wrong? ID are int (in my DB, BookingID is int), and also its readonly it should not be updating in the first place right? --------------------------------Any way to debug whats in "new" values? ItemUpdating? how to do it?
Hi, Can anyone tell me why my Update attempts are not working? Here is my code: <body> <form id="form1" runat="server"> <div> <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateEditButton="True" AutoGenerateRows="False" DataSourceID="SqlDataSource1" DefaultMode="Edit"> <Fields> <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> </Fields> </asp:DetailsView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringListings %>" SelectCommand="SELECT [City] FROM [Listings]" UpdateCommand="UPDATE [Listings] Set [City]=@City WHERE [ListingID]=@ListingGuid "> <UpdateParameters> <asp:Parameter Name="City" /> <asp:Parameter Name ="ListingGuid" /> </UpdateParameters> </asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </div></form> </body> And here is my code behindProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ListingGuid = Request.QueryString("GUID") End SubProtected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated Label1.Text = "updated" Label2.Text = ListingGuidEnd Sub Please let me know what I am doing wrong?
Hi I have a Page with a DetailsView and SqlDataSource. When Editing the DetailsView the Sql;DataSource UpdateCommand does not seem to pick up the @parameters of the form fields. I have used OnItemUpdating to view all Keys/OldValues/NewValues passed into the UpdateCommand but nothing seems to be picked up. When I place a value into UpdateCommand it updates correctly but does not when I use the form. At this stage I have simplified the code down to typical Master-Details Pages (Separate) using a QueryString to filter the SelectCommand. But nothing seems to work. Please help! I have wasted so much time trying to resolve this and I am on deadline and need this to work. Thanks Dave
Hello Am developing a web site using ASP.net 2.0. I have page to manage the employees information in term of viewing, inserting and updating. The problem is that the updating part doesn't work and it didn't give me any error messages. My code is as following: <%@ Page Language="VB" AutoEventWireup="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs)
If (Not e.Exception Is Nothing) Then
ErrorMessageLabel.Text = "An error occured while entering this record. Please verify you have entered data in the correct format." e.ExceptionHandled = True End If GridView1.DataBind() End Sub
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
GridView1.DataBind() End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub
Hi,I'm trying to create a registration page that I've divided into multiple pages (first page for basic details, next page for address, etc.). I insert the record in the first page, and update it in the other pages. I pass the newly created ID to the other pages using the Page.PreviousPage property. In the second page, I have the SqlDataSource configured as "SELECT * FROM [Table] WHERE ID = ?", and the UpdateCommand is "UPDATE .... WHERE ID = ?". In Page_Load, I am updating the SelectCommand to "SELECT ... WHERE ID = " & intID, and the UpdateCommand similarly. The I do a dtlsvw.Databind()But when I go to the next page (the newly created ID is being passed properly), the update doesn't do anything. The new record doesn't contain the values in the detailsview. Can somebody help me out? Thanks,Wild Thing
For some reason I can't make the stars align. Could someone spot the problem here? I'm looking to select the Identity of my last inserted record in the code behind my DetailsView. Here are the relavent bits: Stored Procedure:ALTER PROCEDURE usp_EW_INSERTMajor @StartDate datetime, @Finishdate datetime, @ProjectName nvarchar(1000), @WorkCell nvarchar(1000), @JobName nvarchar(1000), @PartName nvarchar(1000), @StatusID int, @ResponsibleID int, @FacilityID int
AS Set nocount on
DECLARE @ProjectID int /*This saves the bits to the Project table*/ INSERT INTO EW_Project (ProjectTypeID,FacilityID,StartDate,FinishDate,Status,EmployeeID) VALUES(1,@FacilityID,@StartDate,@FinishDate,@StatusID,@ResponsibleID)
/*This saves the bits to the Major table*/
SET @ProjectID = SCOPE_IDENTITY() INSERT INTO EW_MajorBasic(ProjectID,ProjectName,WorkCell,JobName,PartName) VALUES (@ProjectID,@Projectname,@WorkCell,@JobName,@PartName)
Code-Behind: Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted Dim newID As Integer = e.Values("ProjectID") testlabel.Text = newID End Sub
To be clear, everything is working. When I come to this page with an ID, the records display fine (Select works). The Update and Delete work just fine. The Insert works fine too. It's just that the ItemInserted part does not want to grab the ProjectID. Specifically, testlabel displays a Zero.
Hi all,I want to be able to implement what the following site shows in regards to dynamically displaying Data views of various types: http://quickstarts.asp.net/QuickStartv20/aspnet/samples/data/GridViewMasterDetails_vb.aspx I follow everything to the 'T' but for some reason all my data views are showing even before any initial selection is made in the drop down. How can I have certain grids appear only after a selection from another control has been made?Thanks in advance,Nick
I have been stuck on this problem for over a week, and have ripped out about all of my hair, so here it goes.
I am working on a portfolio on a website that administrators are allowed to update, but the public may only view....easy enough? The grid has three parameters; CatID, Descrip, and Pic - as seen below.
Now as I was looking around on the web I saw many people converting the path of the image to binary and the casting it to the DB, and likewise retrieving it from the DB as binary and converting it to an image, the problem is, I don't know how to do this.
Any help to ease my troubles is apprechiated greatly.
Edit: Also I am not totally sure what the '<%Eval("Pic") %>' is doing, it was autofilled for me. Edit again: Another thing, if I replace any of the ImageUrl to an image path on the computer it does fill the space in the gridview/detailsview. However, with both cases I get a Operand type clash: nvarchar is incompatible with image error.
I am using a stored procedure to update data while in detailsview.I am having a rough time. Dont know why this wont workthanks a lotheres my codeALTER PROCEDURE UpdateCustomerInfo ( @CustomerID as INT, @LName as varchar(50), @FName as varchar(50), @Dept as varchar(50)=NULL, @PhoneType as varchar(50)=NULL, @OfficeType as varchar(50) = NULL, @Ext as Int=NULL, @BridgeExt as int=NULL, @Workstation as varchar(50)=NULL, @OldPrinters as varchar(50)=NULL, @NewPrinters as varchar(50)=NULL, @PhoneImg as varchar(50)=NULL, @OfficeImg as varchar(50)=NULL, @Complete as Bit=NULL, @FaxModel as varchar(50)=NULL, @FaxNumber as varchar(50)=NULL, @ConfPhone as varchar(50)=NULL, @ConfExt as varchar(50)=NULL, @ReutersDacsId as Varchar(50)=NULL, @Bloomberg as Varchar(50)=NULL, @NewFloor as Int=NULL, @OldFloor as Int=NULL )AS UPDATE CustomerInfo SET LName = @LName, FName = @FName, Dept = @Dept, PhoneType = @PhoneType, Ext = @Ext, BridgeExt = @BridgeExt, Workstation = @Workstation, OldPrinters = @OldPrinters, NewPrinters = @NewPrinters, OfficeImg = @OfficeImg, PhoneImg = @PhoneImg, Complete = @Complete Where CustomerId = @CustomerId UPDATE Extras SET CustomerID = @CustomerID, FaxModel=@FaxModel, FaxNumber=@FaxNumber, ConfPhone=@ConfPhone, ConfExt=@ConfExt, ReutersDacsId=@ReutersDacsId, Bloomberg=@Bloomberg where CustomerID = @CustomerID RETURN
I have a SQLDataSource bound to a DetailsView. In which event would I catch a Primary Key violation? Would be an event of the SQLDataSource or the DetailsView? And which particular event? A small example would be great. Thx.