|
Hi All Wizards....
I have this code as an entity and it is working perfectly, but now I try to create the collection for this entity... Can't seem to get it rights... Really need help on this... Thank you all in advance...
Actually, what I try to do is this... I can get only 1 record from the db back at a time, but I want to get nultiple return records from the db....
Here comes the sample codes for entity...
namespace Testing.DataLayer
{
[Serializable]
public class Selected_DocType
{
string userID;
string password;
string doctype;
string fileshortdescription;
public string UserID
{
get { return userID; }
}
public string Password
{
get { return password; }
}
public string DocType
{
get { return doctype; }
}
public string FileShortDescription
{
get { return fileshortdescription; }
}
public Selected_DocType( string userID
, string password
, string doctype
, string fileshortdescription
)
{
this.userID = userID;
this.password = password;
this.doctype = doctype;
this.fileshortdescription = fileshortdescription;
}
public static Selected_DocType GetWebSelected_DocType(string userID, string password)
{
Selected_DocType t = null;
using (SqlConnection conn = Database.CreateConnection())
{
SqlCommand cmd = StoredProcs.GetWebSelected_DocType(conn);
cmd.Parameters["userID"].Value = userID;
cmd.Parameters["password"].Value = password;
cmd.ExecuteNonQuery();
t = new Selected_DocType( userID
, password
, (string)cmd.Parameters["DocType"].Value
, (string)cmd.Parameters["FileShortDescription"].Value
);
return t;
}
}
}
}
|
|
|
|
|
I prefer Necromancer rather than Wizard
t = new Selected_DocType( userID<br />
, password<br />
, (string)cmd.Parameters["DocType"].Value<br />
, (string)cmd.Parameters["FileShortDescription"].Value<br />
Of course you are only getting one object because that is all you are creating.
You also need to call ExecuteReader and iterate through the results returned to create all the objects. Learn the difference between ExecuteNonQuery and ExecuteReader and the other methods for SqlCommand
only two letters away from being an asset
|
|
|
|
|
Thank you for your replied...
And, that where I got stuck in.... Using the ExecuteReader to get the records back and using the while {} loop - I am OK with that. But how to:
1. Define the collection for data finding (is it similiar to define an entity?)
2. Populate the records into the collection
Hope you got what I said... Thank again
Oceanic679
|
|
|
|
|
Please do us, and yourself, a favor and go read some books or take a class before posting here again.
We are more than willing to help, but creating a collection and populating it is a very, very basic task.
only two letters away from being an asset
|
|
|
|
|
not problem... thank you for mentioned... Just need an ideas as too many info on the web in the related subject... sometimes make yourself confused...
|
|
|
|
|
Oceanic679 wrote: Actually, what I try to do is this... I can get only 1 record from the db back at a time, but I want to get nultiple return records from the db....
Are you using some sort of entity framework ? If not, then I'd expect to read a table from the DB, iterate over it, and create a list of the type of object.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
No... I am not... I want to create a collection as I already define an entity for single record, and need to know how to do it... Thank you...
|
|
|
|
|
Thank you to you all.... Got it working...
|
|
|
|
|
kindly give me small and simple example of this
Thanks in Advance
|
|
|
|
|
No
only two letters away from being an asset
|
|
|
|
|
Did you even try to google[^]?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Go to your boss, tell him you are unable to do the task at hand due to insufficient education and/or knowledge. Ask him kindly to give the work to someone capable.
|
|
|
|
|
EliottA wrote: Ask him kindly to give the work to someone capable.
You never know, this guy may come back to you asking for code example for saying this to boss
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
This is very difficult. It requires many years of experience.
Only a c# veteran is capable of performing this feat.
Good luck.
|
|
|
|
|
I am working on software in that i need to print certain things....... which is the easy way........ kindly help
|
|
|
|
|
amaankhan wrote: which is the easy way
The easiest way is give us more details. What exactly is "certain things"?
only two letters away from being an asset
|
|
|
|
|
i want to print Employee Details on the paper ok......my question might be stupid....... sorry i am new to programming field...... with no experience
Thanks for reply
|
|
|
|
|
It's not your ability to program or the fact that the question may be stupid. The problem is your ability to communicate a complete idea so someone can figure out exactly what you're talking about.
|
|
|
|
|
Print to where? To a screen or to a printer? Please read the forum guidelines and rephrase your question.
|
|
|
|
|
i have to print the Employee Details on the paper
|
|
|
|
|
|
ha ha .. .best of all ...
|
|
|
|
|
|
It sounds like you need to write a report. I'd suggest that you read up on this using Google.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Printing on-screen and sending to the printer are very similar. You need to use the System.Drawing namespace, in particular the Graphics class. Then hook a PrintDocument's main event (can't remember the name) and paint onto the page. Don't forget to take the page settings into account.
|
|
|
|