Results 1 to 8 of 8

Thread: display for current user AND update command

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    display for current user AND update command

    i want the textbox to display to the current user,
    (who has logged in using username and password )


    visual basic code: Dim cmdselect As SqlCommand cmdselect = New SqlCommand("SELECT msg_default from tb_comp_detail ", oSQLConn) txtDefault.Text = cmdselect.ExecuteScalar().ToString()


    can i just put in an sql that says "select msg where current user"
    DOES ANYONE HAVE ANY IDEAS

    i.e. at the minute the txtbox displays the first row in the database
    i want the textbox to display the information for the current user

    also what the problem with this update

    Line 1: Incorrect syntax near '('.

    Line 81: Dim sqlSaveMsg1 As New SqlCommand("update tb_comp_detail (msg_custom1) Values ( txt_msg1.text );", oSQLConn)
    Line 82: oSQLConn.Open()
    Line 83: sqlSaveMsg1.ExecuteNonQuery()
    Line 84: oSQLConn.Close()
    __________________
    __________________
    im a newbie so be nice
    Last edited by d2005; Sep 12th, 2005 at 06:08 AM.
    it works 60% of the time, all the time.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: display for current user AND update command

    I'd do a Google search for Forms Authentication. It's ASP.NET's built in authentication system that will handle everything you want.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: display for current user AND update command

    can i show you some of my code
    i have the forms authentication working

    but im not too sure of how to work with it, i.e. only let the logged in user view thier own information.
    Last edited by d2005; Sep 12th, 2005 at 08:58 AM.
    it works 60% of the time, all the time.

  4. #4

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    im showing the code anyways

    if anyone knows then how to display specific info then that would be great.

    my webconfig
    Code:
        -->
        <authentication mode="Forms" /> 
    
        -->
        <authorization>
            <deny users="?" /> <!
    
    ..........
       <sessionState 
                mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
                cookieless="false" 
                timeout="20"
    my login page
    Code:
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
            If companyDB.ValidateUser(txtUsername.Text, txtPassword.Text) Then
                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkAutomatic.checked)
            Else
                lblError.Visible = True
                lblError.Text = "incorrect username and password, " _
                & " please try again."
    
            End If
    my companydb
    Code:
    Public Shared Function ValidateUser(ByVal UserName As String, ByVal Password As String) _
                As Boolean
            Dim sSelect As String
            sSelect = "SELECT COUNT(*) FROM tb_comp_detail " _
                    & "WHERE companycode = '" & UserName _
                    & "' AND comp_password = '" & Password & "'"
            Dim cmdSelect As New SqlCommand(sSelect, Connection)
            Dim iCount As Integer
            cmdSelect.Connection.Open()
            iCount = cmdSelect.ExecuteScalar()
            cmdSelect.Connection.Close()
            If iCount = 0 Then
                Return False
            Else
                Return True
            End If
        End Function
    an example of a user control
    Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            If Not IsPostBack Then
                If Page.User.Identity.IsAuthenticated Then
                    lblheader.Text = "Home Page For - "
                    lblheader.text &= Page.User.Identity.Name & "."
                End If
            End If
        End Sub
    the question really is
    if i have textboxes in the webform,
    how can i display data only for the user that is currently logged in,
    how do i use the session which is created when they log in, as in the user control.

    PLEASE TELL ME IM GOING ABOUT THIS THE RIGHT WAY
    it works 60% of the time, all the time.

  5. #5
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: display for current user AND update command

    Yes you are on the right lines.

    Basically the Username is your unique identifer for all users. This is being stored in Page.User.Identity.Name after the user has successfully been logged in. So therefore any queries you make against the database need to be passed Page.User.Identity.Name to personalise the query.

    Looks like you are on the right track - are you just wanting to be reassured or do you have a specific problem?

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  6. #6

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: display for current user AND update command

    lol, yes i have a specific problem,
    if i can do this one thing i should be able to do it for all pages etc....
    this webform for example has a few textboxes
    i want these textboxes to diplay ( eventually i want them to update also)
    the users specific messages,

    my page load event
    Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            If Not IsPostBack Then
                If Page.User.Identity.IsAuthenticated Then
                    BindDefaultMessage()
    
    
                End If
            End If
    my bind textbox
    Code:
    Private Sub BindDefaultMessage()
    Dim cmdselect As SqlCommand
            cmdselect = New SqlCommand("SELECT msg_default from tb_comp_detail ", oSQLConn)
            txtDefault.Text = cmdselect.ExecuteScalar().ToString()
    i think the textbox i have coded just displays the first row,

    no where on this form have i stated if this is the user logged in then display thier custom msg. i.e. a message that they have saved in the database

    how do i use the login i have set up to that effect
    it works 60% of the time, all the time.

  7. #7

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    another example

    a good example of what i need is this

    i have a table with company code drivername and driver reg

    i have a form with only 2 textboxes,
    for drivername and driver reg

    companycode is the username that was used to log in

    i want to write to the database

    the logged in user to companycode(automatic)
    then the details they entered to drivername and driver reg

    the code i have is as below - NB tester was just to check it was working

    Code:
    Dim sqlcompDrivers As New SqlCommand("INSERT INTO tb_comp_drivers(companycode,driver_fname,Registration)  VALUES('tester','" & txtDriverName.Text & "','" & txtDriverReg.Text & "');", oSQLConn)
            oSQLConn.Open()
            sqlcompDrivers.ExecuteNonQuery()
            oSQLConn.Close()
    this is an example of my needs
    it works 60% of the time, all the time.

  8. #8

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    i did this but surely its not the way to do things

    i made a label,
    gave its text a value

    Code:
       Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            Session("company") = Page.User.Identity.Name
            LblUser.Text = Page.User.Identity.Name
    then my insert looks like this
    Code:
    Dim sqlcompDrivers As New SqlCommand("INSERT INTO tb_comp_drivers(companycode,driver_fname,Registration)  VALUES('" & LblUser.Text & "','" & txtDriverName.Text & "','" & txtDriverReg.Text & "');", oSQLConn)
            oSQLConn.Open()
            sqlcompDrivers.ExecuteNonQuery()
            oSQLConn.Close()
    thats not a great bit of programming but it works,
    is there other ways to do this
    it works 60% of the time, all the time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width