Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 23rd, 2008, 01:03 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to update a label controll from a db

Hi there i need to pull data from a database for each individual user account and show it to a label controll or any controllon in which the loged user can see its posts which will varey from user to user, something similar to the wrox forums, each registred user has a diferent number of posts/replays last visit etc.only that has to be visible to the user only


any help apprisiated
__________________
bx
  #2 (permalink)  
Old December 23rd, 2008, 01:12 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default What part...

what part do you need help with? connecting to the database? retrieving the data? assigning the data to the label? We need more info, like what database are you using and what part specifically do you need help with? what do you have so far?
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #3 (permalink)  
Old December 23rd, 2008, 01:36 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I have a sql2005 DB the tabel has an ID ,Name, Surname and Contact column.
In the Contact column is stored the user name, i need too count the usernames in that column and show them as int for each loged user.

exampel: my user name is bex and in the contact Column bex exists lets say 5 times now the label in default.aspx should display 5;

1)i need help with retrieving the data
2)may be conversion to int..


thanks for you quick replay
__________________
bx
  #4 (permalink)  
Old December 23rd, 2008, 01:50 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default So...

you need help with the query to find the count?


Select Count(UserName) As ContactCount From tblUsers Where UserName=@UserName

this here is searching your database for users with the username supplied by you (@UserName is the search parameter) and counting them all up and returning that count

does that help you with what you need or do you also need the code to connect to the db run this query and return that data? if so what language?
C#? VB.net?
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #5 (permalink)  
Old December 23rd, 2008, 01:58 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

VB plase
i need to call that on page load
__________________
bx
  #6 (permalink)  
Old December 23rd, 2008, 02:28 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default I would..

I would create a function that get's the users count then call that function on the page load. I'm going to assume you are storing the username in a session variable and assume your table names as well. This code is just an example of what to do you would need to adapt it to suite your needs.

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       If Not Page.IsPostBack Then
          Dim Count As String = GetUserCount(Session("UserName").ToString).ToString

          If Not String.IsNullOrEmpty(Count) Then
               lblUserCount.Text = Count
          Else
               lblUserCount.Text = "Sorry could not retrieve count."
          End If

        End If

End Sub
In the above code i am calling the function GetUserCount and passing the username which i assume is stored in a session variable and assigning it's return value to a variable named Count. I then check if that variable has a value. If it does then I assign the label lblUserCount text the count. If there is no value for count I tell the user with the text of the label.


Below is the actual GetUserCount function. First I create my connection to the DB then my query and my reader. I then create a string variable and assign it the UserName value. I then check to make sure it has a value if not i dispose of all the variables then return nothing and exit the function.
otherwise i open my connection run the query check to make sure that i return rows then if there are rows i return the result of the query. then close my connection and reader and dispose my variables.
Code:
Private Function GetUserCount(ByVal UserName As String) As String
        
        Dim sqlCon As New System.Data.SqlClient.SqlConnection("Connection String Here")
        Dim sqlCmd As New System.Data.SqlClient.SqlCommand("Select Count(UserName) As UserCount From tblUsers Where UserName=@UserName")
        Dim sqlDR As System.Data.SqlClient.SqlDataReader = Nothing

        Dim strUserName As String = Nothing

        Try
            strUserName = UserName
        Catch
            strUserName = Nothing
            Count = Nothing
        End Try

        If String.IsNullOrEmpty(strUserName) Then
            sqlCon.Dispose()
            sqlCon = Nothing
            sqlCmd.Dispose()
            sqlCmd = Nothing
            sqlDR = Nothing
            strUserName = Nothing
            Count = Nothing
            Return Nothing
            Exit Function
        End If

        Try
            sqlCon.Open()
            sqlCmd.CommandType = CommandType.Text
            sqlCmd.Parameters.AddWithValue("@UserName", strUserName)
            sqlCmd.Connection = sqlCon
            sqlDR = sqlCmd.ExecuteReader
            sqlDR.Read()

            If sqlDR.HasRows Then
              Return sqlDR("UserCount").ToString
            End If

         Finally
            sqlDR.Close()
            sqlDR = Nothing
            sqlCmd.Dispose()
            sqlCmd = Nothing
            sqlCon.Close()
            sqlCon.Dispose()
            sqlCon = Nothing
            strUserName = Nothing
        End Try
End Function
Like I said this is an EXAMPLE you would have to adapt it to suite your structure and names. But this should give you a pretty good Idea. There may be some overkill in there but i like to to be safe rather than sorry.
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #7 (permalink)  
Old December 23rd, 2008, 03:01 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Thanks that is what i was looking for.
can i ask you somethig about aspnet database? if i can do you know how wto delete a user from ASPNet DB.
thanks agen for the code
__________________
bx
  #8 (permalink)  
Old December 23rd, 2008, 03:09 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Sorry...

But I never use that database... perhaps you could start a new thread and someone else can help.
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #9 (permalink)  
Old December 23rd, 2008, 07:36 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there.. What do you mean?? you want to delete a user from the user management database? again, you want to do it in code, or just in the database??
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
  #10 (permalink)  
Old December 24th, 2008, 06:35 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I just want to delete the user from the db so it can not log in next time the user attempts to log in.
__________________
bx
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to upload Files using inet controll in VB dadahonde VB How-To 5 April 11th, 2006 11:16 PM
postback of a particular Controll not whole page Raz Muhammad General .NET 1 November 29th, 2004 12:42 PM
Call Script function in server controll qadeerahmad General .NET 1 September 26th, 2004 11:09 PM
Image controll shows icon not pic Raif Access 2 June 22nd, 2004 01:44 PM
Auto update of text box/label Simon Dilley Classic ASP Basics 1 June 6th, 2003 07:00 AM



All times are GMT -4. The time now is 11:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.