display data from a database in a label
-
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
-
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
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"
-
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"
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
-
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
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
-
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
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.