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
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
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.
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
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
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
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