|
Thanks PIEBALDconsult. I was just typing my response to Luc when your answer came through, and it is in fact exactly what I ended up doing.
I've been ignoring UserControls for too long and it seems I've now paid the price for it as I'll have to do a fair bit of work to change all my custom TabPages to custom UserControls. You live and you learn.
I still have the problem of not being able to edit a control in Designer that implements an abstract control but I can live with that for the moment (see my response to Luc) - unless of course you know a better workaround for that?
|
|
|
|
|
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email.
Any help is highly appreciated..
Thanx inadvance,
Tash
|
|
|
|
|
Plain logic :
Iterate over datset/datatable rows. Get data from each row format/align as your need.
And append this in email body.
Like
StringBuilder sb = new StringBuilder();
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName"].ToString());
}
|
|
|
|
|
Thanx for the reply, Have you got any sample codes to share???
regards,
Tash
|
|
|
|
|
I know this going to come !!
Check my previous reply, i edited it.
|
|
|
|
|
Thanx a lot dude... now have to work on it..
Thanx alot..
|
|
|
|
|
is it possible to display as the table as such with the column names and all..??
|
|
|
|
|
<<tash18>> wrote: is it possible to display as the table
If by this you mean show in a tabular format like
Col1 Col2
1 A
2 B
As i said you have to format the o/p as you want to show.
foreach (DataColumn dc in ds.Tables["TableName"].Columns)
{
sb.Append(dc.ColumnName);
sb.Append(" ");
}
sb.Append(Environment.NewLine);
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName1"].ToString().PadRight(20,' '));
sb.Append(item["columnName2"].ToString().PadRight(20,' '));
sb.Append(Environment.NewLine);
}
May be their better way then this !!
|
|
|
|
|
Most mail systems know how to handle HTML, so you could get a real table by adding some TABLE, TR, TD tags.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I usually write the data to an XML file and attach it. The receiver can then use XSLT to transform the data to HTML, CSV, etc.
|
|
|
|
|
Hello
I want to set a streamreader to read from some stream source (file)
if i put the file in the root directory (bin/Debug/fileName) works fine.
but what if i put the file in some folder within the debug folder (bin/Debug/SomeFolder/fileName) how i can declare the path in this case ?
Thanks
|
|
|
|
|
When file paths aren't absolute (i.e. they don't start at some root point such as C:\), then they are relative to the "current directory" which is some folder, initially most often defaulting to where your EXE is located. If so, @"SomeFolder\fileName" would suffice. However:
1. the initial "current directory" can be different from your EXE's location, e.g. by using an Explorer shortcut with an explicit "current directory" specification.
2. the "current directory" can change at run-time, e.g. if you use a OpenFileDialog, switch folders there, and the code allows this change to persist;
3. it is in general unwise to locate files relative to your EXE's location, as the EXE often gets installed in a location that is (a) shared by multiple users, and (b) not always writable by regular users.
The recommended approach is to give files a specific location, independent of your EXE's location. Microsoft has some guidelines for such folders, and offers some means to get those paths, see Environment.GetFolderPath() . Part of the guidelines is you should create subfolders based on your (or your company's) name, and your product name.
Example:
string folder=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
folder=Path.Combine(folder, "companyName");
folder=Path.Combine(folder, "productName");
Directory.CreateDirectory(folder);
string file=Path.Combine(folder, "document.txt");
File.WriteAllText(file, "this is a file creation demo");
Console.WriteLine("Successfully created file "+file);
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
i'll get deeper into ur answer tomorrow (to late in my place)
meanwhile i solved it this way: Path.Combine(Directory.GetCurrentDirectory(), "Resources/XML/newTest_NewDesign.xml");
Thanks
|
|
|
|
|
igalep132 wrote: Directory.GetCurrentDirectory(),
This is about the worst way you can do this. The thing everyone doesn't realize about GetCurrentDirectory is that the currect directory can unexpectedly change or start in a folder you didn't expect to begin with. Don't make the mistake of believing that just because your app was just launched and the first thing you did was GetCurrentDirectory that you're going to get the path to the folder your .EXE was launched from. What if someone created a shortcut to your app and set the "working directory" to C:\Windows? Guess which folder GetCurrentDirectory is going to return...
Use Luc's example and build the path correctly. Don't use string concatentation to build the folder path either. Use Path.Combine instead.
|
|
|
|
|
do you really use it ?
why i need to learn new syntax to get lower performance ?
when i have no time and the high performance is not a must i go for the Dataset.
its ok with the collections and arrays but with the database !!
what do you think ? regardless that i am late to ask this
|
|
|
|
|
Tamimi - Code wrote: why i need to learn new syntax to get lower performance ?
Who says the performance is lower? A well designed entity query can be as performant as a hand designed SQL query.
You don't need to use the new syntax - it's entirely up to you. Linq2Entities does not replace ADO.NET; it's just another tool in your arsenal. Use it, or not; that's entirely up to you.
|
|
|
|
|
while its not replacing anything and have no performance benefits, why its exist ?
i am asking this because the lambda expression is hard
thank you
|
|
|
|
|
It's for lazy people who don't want to type much and want to exhibit their cutting-edge skillz.
|
|
|
|
|
It exists to bring database functionality into the realm of coders who may have limited SQL skills, by integrating query capabilities into a language they are comfortable with.
Tamimi - Code wrote: i am asking this because the lambda expression is hard
That's just being lazy. Lambda expressions are not just for L2E, so you really should learn them.
|
|
|
|
|
I like LINQ, it can save a lot of time. Especially if you are using LINQ to SQL. But I really like the simple things such as counting specific values in a list...
int count = list.Count(c => c.Value > 10);
much nicer and quicker than...
int count = 0;
foreach(CustomClass c in list)
{
if(c.Value > 10)
count++;
}
Illogical thoughts make me ill
|
|
|
|
|
And what do you think it's doing in the background?
musefan wrote: it can save a lot of time
Coding time, yes. Maybe not execution time (have you benchmarked it?). Maybe not maintenance time if the next person to touch the code doesn't understand it.
I'll stick with simpler code.
|
|
|
|
|
Yes, I did mean quicker to code and I understand that it will be doing a similar if not identical thing in the background.
I did just do a test and the foreach loop is around 3 times quicker than the LINQ query (in this case), but for general use I think the faster development time is worth it, and it is better maintenance - if the next person didn't understand then it would become time for them to learn
Anyway, if performance became important then there would be a lot more general style coding stripped away I am sure.
Illogical thoughts make me ill
|
|
|
|
|
Good point. LINQ is usually slower when I've dabbled with it. And although more verbose I always prefer simple explicit code, less error prone, easier for others to understand and easier to debug.
Regards,
Rob Philpott.
|
|
|
|
|
|
Tamimi - Code wrote: when i have no time and the high performance is not a must i go for the Dataset
That's no reason to use a DataSet... in fact there pretty much is no reason to use a DataSet.
"If you don't have time to do it right, when will you have time to do it over?"
|
|
|
|