|
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"
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
Hi Guys; Anyone have an idea how to retrieve the string value of an object's property?
For instance, assume an object instance of type "Inspection" named _inspection, which has a property called "Region" of an unassuming type.
Any idea how to get the string value "Region" from
this._inspection.Region
(more information than is necessary...I'm trying to build type-safety into the column names of a GridView)
"I need build Skynet. Plz send code"
|
|
|
|
|
Have a look at this : [^]
A dogged, arrogant belief in self and the childlike idealism that comes with not knowing my limits. This is my greatest blessing, my priceless attribute.
|
|
|
|
|
...I was actually hoping that there was a solution that didn't involve reflection. I mentioned that in my original post, but edited it out to keep the suggestions open.
I mean, you can get the string representation of an enum with the following:
[Enum].GetName(typeof([LIB].Enumerations.InspectionStatusType), Me._inspection.Status)
(and that is in the mscorlib.)
Isn't there any way to retrieve the string evaluation of an object's property without reflection yet?
"I need build Skynet. Plz send code"
|
|
|
|
|
Enum.GetName uses reflection internally. Reflection IS the retrieval of code metadata...which includes the name of a property. Thats the entire purpose of reflection...
|
|
|
|
|
Jon Rista wrote: Enum.GetName uses reflection internally
ah, good to know. Thanks
"I need build Skynet. Plz send code"
|
|
|
|
|
i will tell the requirement in detail.
i have spooled some record in one datatable, in score.cs class.
i have to print that report in other windows form name report.cs(which is a windows form where i kept my crystal report viewer)
now i want to access my datatable in the score.cs.
for this i have to inherit those things.
like public partial class report:score,
instead of public partial class report:form,
but if i do so i m getting error that my form is not showing,as form is a class we cannot remove that.
can you please guide me how to access my datatable??
|
|
|
|
|
Well this site is an excellent database in itself of some very useful articles pertaining to connecting to databases programmatically, give CodeProject a search or two
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Hello Fellow Coders;
I'm still struggling with some of the concepts of the treeview in C#. I found this code whick works great. I am trying to figure out how to assign values to the nodes that get added such as the name, text,tag, imageindex, tooltip etc.
This sample is using the TreeNodeCollection can I assign the above properties using this collection??
Here is the code....
TreeNode AddNode(TreeNodeCollection Parent, string text)
{
foreach (TreeNode node in Parent)
{
if (node.Text == text)
return node;
}
return Parent.Add(text);
}
void InsertNodes(TreeNodeCollection treeviewNodes, List<string> _nodes)
{
if (_nodes.Count == 0)
return; //Recursive exit
TreeNode TempNode = AddNode(treeviewNodes, _nodes[0]);
_nodes.RemoveAt(0);
InsertNodes(TempNode.Nodes, _nodes); //Recursive calling
}
private void button1_Click(object sender, EventArgs e)
{
List<string> NODES = new List<string>(); //Save nodes
string[] strArr = textBox1.Text.Split('\\');
foreach (string str in strArr)
NODES.Add(str);
InsertNodes(treeView1.Nodes, NODES);
}
Thanks In Advance
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Please use pre tags for code blocks. It makes the reading easier.
The first method return the node added so you can use it's properties on the calling side:
...
TreeNode addedNode = AddNode(MyTreeView.Nodes, "New node text");
addedNode.Tag = "XYZ";
addedNode.ImageIndex = 123;
...
Or if you want, add a variable inside the method and assign the properties you want in the method:
TreeNode AddNode(TreeNodeCollection Parent, string text)
{
TreeNode temporaryNode;
foreach (TreeNode node in Parent)
{
if (node.Text == text)
return node;
}
temporaryNode = Parent.Add(text);
temporaryNode.Tag = "XYZ";
temporaryNode.ImageIndex = 123;
...
return temporaryNode;
}
The same idea goes with the other method.
In all cases you may have to add parameters to the methods or extra logic how you decide what tag, imageindex etc is set.
This is quite basics, so I think you should get a good book concerning C# programming.
|
|
|
|
|
Thanks for this answer...I will try it out.
I have read
Visual C#.Net by Williams MS Press
And currently reading
Programming Visual C# 2008 by Marshall MS Press
Can you recommend a book??
Thanks
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
|
Thanks;
I had tried your suggestion before asking the questions but in looking at your reply realized that I was doing it in the wrong place.
Here is what worked..
TreeNode AddNode(TreeNodeCollection Parent, string text)
{
TreeNode temporaryNode;
foreach (TreeNode node in Parent)
{
if (node.Text == text)
{
return node;
}
}
temporaryNode = Parent.Add(text);
temporaryNode.Name = text;
temporaryNode.Text = text;
temporaryNode.Tag = "XYZ";
temporaryNode.ToolTipText = "XYZ";
temporaryNode.ImageIndex = 123;
temporaryNode.SelectedImageIndex = 123;
return temporaryNode;
//
return Parent.Add(text);
}
Thanks Again
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Glad if it helped
|
|
|
|
|
As a followup for anyone reading this. This part of the above code has unexpected results.....
temporaryNode = Parent.Add(text);
temporaryNode.Name = text;
temporaryNode.Text = text;
temporaryNode.Tag = "XYZ";
temporaryNode.ToolTipText = "XYZ";
temporaryNode.ImageIndex = 123;
temporaryNode.SelectedImageIndex = 123;
return temporaryNode;
But on the whole if you are looking for a recursive way to add tree nodes the orginally posted code works great. It's just not full featured.
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Hi experts.
I wanna create a Win App that needs a simple database, just for saving plain text and plain numbers.
Now i don't know which one is better ! sdf Database , or mdf database or XML.
What's your suggest ?
Could u guide me ?
Thank you.
|
|
|
|
|
|
What about SQLite? It's also used by Firefox 3 for storing passwords and other data.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This is really a matter of opinion, so here's mine:
- for single user application with small amount of local data => SQL Server Compact Edition
- for multi user application with medium amount of shared data => SQL Server Express / Oracle XE
- for multi user application with large amount of shared data => SQL Server Std or Enterprise / Oracle 11g
I believe that the next question you would have is: what is a small or large amount of data. Again a matter of opinion but perhaps some quantities (these are certainly not accurate but give some idea):
- small amount could be less than 1 GB, perhaps less than a hundred tables and no table contain over 10 000 rows
- large amount could be more than 4 GB of actual data, perhaps 500+ tables tables and and some tables contain over 10 000 000 rows. User amount is high, let's say over 1000 concurrent.
I already regret that I wrote any quantítative information since it's really not that simple (also consider licensing, support level, activity levels, transaction counts etc.) but I'm prepared to get flamed
|
|
|
|
|
|
You're welcome
|
|
|
|