Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. display data from a database in a label

display data from a database in a label

Scheduled Pinned Locked Moved C#
tutorialdatabasehelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ferronrsmith
    wrote on last edited by
    #1

    I a noob, just to get that clear. Here is what i wanna accomplish. I retrieve a user id via a connection string, i want to used that id to call a stored procedure that then bring back the user's fname, last, add etc in my labels, do any of you have any example or guide on how to do this, guys i really need help and thanks in advance.

    Ferron

    A 1 Reply Last reply
    0
    • F ferronrsmith

      I a noob, just to get that clear. Here is what i wanna accomplish. I retrieve a user id via a connection string, i want to used that id to call a stored procedure that then bring back the user's fname, last, add etc in my labels, do any of you have any example or guide on how to do this, guys i really need help and thanks in advance.

      Ferron

      A Offline
      A Offline
      Alaric_
      wrote on last edited by
      #2

      So you have "in your hand" a user ID and you want to be able to send it down to a stored proc to lazy-load[i.e. "load on demand"] the user's data? There are several things that could be done, but the solution to this problem can be very rudimentary or quite complex. It is important to know what the kernel of your code-base looks like in order to cater a solution to your specific app. What have you tried so far? What isn't working?

      "I need build Skynet. Plz send code"

      F 1 Reply Last reply
      0
      • A Alaric_

        So you have "in your hand" a user ID and you want to be able to send it down to a stored proc to lazy-load[i.e. "load on demand"] the user's data? There are several things that could be done, but the solution to this problem can be very rudimentary or quite complex. It is important to know what the kernel of your code-base looks like in order to cater a solution to your specific app. What have you tried so far? What isn't working?

        "I need build Skynet. Plz send code"

        F Offline
        F Offline
        ferronrsmith
        wrote on last edited by
        #3

        well i know how to create the query string. Just need to know how to create the stored procedure and place the data in the necessary labels

        Ferron

        F C 2 Replies Last reply
        0
        • F ferronrsmith

          well i know how to create the query string. Just need to know how to create the stored procedure and place the data in the necessary labels

          Ferron

          F Offline
          F Offline
          ferronrsmith
          wrote on last edited by
          #4

          do you know where i could get a good guide or can you point me to a online tutorial that can do this, thanks guys

          Ferron

          1 Reply Last reply
          0
          • F ferronrsmith

            well i know how to create the query string. Just need to know how to create the stored procedure and place the data in the necessary labels

            Ferron

            C Offline
            C Offline
            CodingYoshi
            wrote on last edited by
            #5

            Here is one way, but there are many: public class User { private string _firstName; private string _lastName; private string _id; // or int not sure what type yours is public void Load(string id) { UserManager manager = new UserManager(); manager.Retrieve(this); } // properties and other methods } public class UserManager() { public void Retrieve(User userToRetrieve) { SqlCommand cmd = new SqlCommand(); cmd.Text = "SELECT FirstName, LastName FROM UserTable WHERE UserID = '" + id + "'"; // Here use an adapter and fill a DataTable // If the DataTable has rows then assing the proper columns to the userToRetrieve object // If no rows then throw an exception to advise no User was found with the given id. } } You UI code can be something like this: User aUser = new User(); string id = "123"; try { aUser.Load(id); this.LabelID.Text = aUser.ID; this.LabelFirstName.Text = aUser.FirstName; this.LabelLastName.Text = aUser.LastName; } catch(SomeException ex) { MessageBox.Show(ex.Message); } If you still can not do it then buy a book on C#. Please note this code might have errors but it is just to give you an idea.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups