|
arkiboys wrote: Not sure what I am doing wrong.
This is happening because you are writing one column at a time to your file. You need to be writing one row at a time. This example loops through the rows of a table, then loops through the columns, adds the value to a string, and tacks on a comma at the end, then goes to the next. When it is done with all the columns in a row, it writes the row to the file, and moves on to the next. Hope this helps.
for (int r = 0; r < someTable.Rows.Count; r++)
{
for (int c = 0; c < sometable.Columns.Count; c++)
{
strWriteText += string.Format("{0},", someTable[r][c].ToString());
}
File.AppendAllText(strFilePath, string.Format("{0}{1}", strWriteText, Environment.NewLine), Encoding.UTF8);
strWriteText = string.Empty;
}
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
I do not get one column per row. As explained, I get the first three fields in the first row, then each column in a separate row.
This is what I have in case you spot anything. Thanks
public static void SavePrices(List<clsSecurityPricing> securities)
{
// if the directory doesn't exist, create it
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
// create the output stream for a text file
StreamWriter textOut =
new StreamWriter(
new FileStream(path, FileMode.Create, FileAccess.Write));
// write each Security Price...
foreach (clsSecurityPricing SecurityPricing in securities)
{
textOut.Write(SecurityPricing.Security_ID + ",");
textOut.Write(SecurityPricing.Security_Name + ",");
textOut.WriteLine(SecurityPricing.Bid_Source + ",");
textOut.WriteLine(SecurityPricing.Bid_Size_Best_Latest + ",");
textOut.WriteLine(SecurityPricing.Bid_Price_Best_Latest + ",");
textOut.WriteLine(SecurityPricing.Ask_Price_Best_Latest + ",");
textOut.WriteLine(SecurityPricing.Ask_Size_Best_Latest + ",");
textOut.WriteLine(SecurityPricing.Ask_Source + ",");
textOut.WriteLine(SecurityPricing.Bid_Price_Best_AllDay + ",");
textOut.WriteLine(SecurityPricing.Ask_Price_Best_AllDay);
}
// write the end of the document
textOut.Close();
}
|
|
|
|
|
Check here:
arkiboys wrote:
. . .
textOut.Write(SecurityPricing.Security_Name + ",");
textOut.WriteLine(SecurityPricing.Bid_Source + ",");
. . .
Write writes the specified string to the stream, WriteLine writes the string to the stream and then appends a New Line.
|
|
|
|
|
|
Ew; other than his mistaken use of WriteLine rather than Write, his is better than yours.
|
|
|
|
|
Hi!
According to MSDN by using MethodInfo.Invoke I can invoke public properties. But how about methods having Internal or Private access modifiers? Is there a way that I can Invoke them?
Thanks!
|
|
|
|
|
Yes. Once you get the methodinfo you are able to invoke them reflectively, but you need to have permission to do so. For example, you can't invoke private member 'foo' of class 'A' from any other class (I think, but I am CERTAIN that you can invoke 'foo' from within class 'A' because I have done it).
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi!
With the help of BindingFlags I managed to do what I need. So, you can get a private, internal, or basicaly non-static methods by using BindingFlags parameters either from the same class or from a different class.
The code below writes "ClassA's internal Method1 invoked." two times on the console.
Thanks!
class ClassA
{
internal void Method1()
{
string message = "ClassA's internal Method1 invoked.";
Console.WriteLine(message);
}
public void MethodInvoker ()
{
Type typeOfClassA = (new ClassA()).GetType();
//GET the internal Method1 of ClassA:
MethodInfo methodToInvoke = typeOfClassA.GetMethod"Method1",BindingFlags.Instance|BindingFlags.NonPublic);
methodToInvoke.Invoke(this, null);
}
}
class ClassB
{
public static void InvokeMethod2InClassA ()
{
ClassA classAObject = new ClassA();
Type typeOfClassA = classAObject.GetType();
//GET the internal Method1 of ClassA from ClassB:
MethodInfo methodToInvoke = typeOfClassA.GetMethod("Method1", BindingFlags.Instance | BindingFlags.NonPublic);
methodToInvoke.Invoke(classAObject, null);
}
}
class Program
{
static void Main(string[] args)
{
ClassA invoker = new ClassA();
invoker.MethodInvoker();
ClassB.InvokeMethod2InClassA();
Console.ReadLine();
}
}
|
|
|
|
|
Hmmm, very interesting. I had no idea you could invoke methods using reflection that you otherwise would not have access to. I knew you could FIND the private methods of other classes in the way you presented, but I expected the environment to throw an exception if I tried to invoke them. Anyway, this is very interesting. Just as an aside, I feel obligated to tell you that there is an operator "typeof" that can get the type of a class without you needing to instantiate it. Therefore, you can convert "(new ClassA()).GetType()" to "typeof(ClassA)". This alleviates you from needing to instantiate, then throw away, some class.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
If ClassA and ClassB are in the same file, then ClassB has access to ClassA's internal members anyway, so there's nothing unusual going on here.
|
|
|
|
|
Someone on here has said you can, but I still don't believe it.
|
|
|
|
|
Hi,
I've implemented DragDrop functionality between two DataGridViews using the MouseDown event. The problem is both Grids have DataGridViewCheckBoxColumns and DataGridViewComboBoxColumns, which require that the user be able to click on the objects contained in those columns and change them as needed. The MouseDown event is preventing these objects from reacting to the user's MouseClick. I need a way to implement DragDrop between two grids without disrupting the DataGridView's ability to handle normal MouseClick events. I'm looking for a different event that could be used to handle the DragDrop. Any help is appreciated. Thanks!
|
|
|
|
|
Hi guys!
I was wondering. When I have a reference to a dll in my program and I change that dll, do I have to re-compile every app that uses that dll? I am trying to create re-usable code that I can call from many apps (5 +) and won't have to recompile all of them when I change code in a common location. I am trying not to use a webservice as the objects are quite large.
|
|
|
|
|
If you have given the DLL's reference, then you need to refresh that DLL in client projects your self.
Instead, if you give the reference of the Class Library Project itself, then this operation is handled for you.
Hope I am clear enough.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
I have a small app that emails me a message every morning. I recently had to change the SMTP port from 25 to 587 on our server due to spam. So I went into the code and changed the SmtpMail.SmtpServer = 192.168.1.15 to 192.168.1.15:587. I am getting this error:
The server response was 421 Cannot connect to SMTP server 192.168.1.15 (192.168.1.15:25), connect error 10061.
It seems it is still trying to access on port 25. I looked around a bit, but could not find anything on how to change the port it uses. I thought adding the port to the end of the IP address would be sufficient.
Thanx in advance
Jude
|
|
|
|
|
Hi,
Surprised to know that you are still using .Net framework 1.0 / 1.1.
In v1.0 or v1.1 you need to set Fields property of MailMessage class's instance for changing default port like this --
objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", NewServerPort)
NewServerPort will be your port; in your case 587.
Also objMessage is instance of MailMessage class.
I will recommend you to use .Net 2.0 framework for sending mails, because it exposes appropriate properties for everything related to mails.
There is a change in namespace and the new one is - System.Net.Mail.
Hope this helps !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Thanx a lot!
I am not an all day coder. I write little apps and scripts to help me out through the daily grind. I do the tech support work for a small business and my main job is keeping everything running smoothly and handling all the computer problems when they arise.
I have .Net 2.0 installed, but how do I use it in VS2003?
Jude
|
|
|
|
|
Hi,
I am afraid, but you cannot use .Net Studio 2003 for developing applications on framework 2.0. For that you will need VS.NET 2005 or VS.NET 2008. I think 2008 is a better choice since it can be used to develop applications that target all framework versions.
Of course, the choice is yours (rather your company's)
Hope this helps.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Thats what I thought. I installed VS2005 a while back, but it was buggy and a resource hog, so I uninstalled and stuck with 2003.
I got a beta disk of VS2008 from MS last month, but have yet to play with it.
What about with Monodevelop?
Jude
|
|
|
|
|
TheJudeDude wrote: resource hog
Just curious about your machine configuration
TheJudeDude wrote: What about with Monodevelop?
I have no idea about Monodevelop. I havent used it yet.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Abit VA-20, AMD Barton 2800+, 2GB Corsair DDR 400, 78 GB Raptor. Runs photoshop pretty good, and that is a horse.
Jude
|
|
|
|
|
Hi,
I'm not sure this problem belongs here, but this is probably just as good a place as any for it.
Anyway. I'm working on a solution (written in C#) which uses the SQL Express database. I'm working with it in the Server Explorer, but the problem is that each time I start debugging, I must first manually right-click the connection to the database in the Server Explorer and select "Close Connection". Otherwise I get an error when I try to connect to it using my app (which is a web application, not sure if that matters). Which becomes quite annoying after some time. Is there a way to automatically close the connection when I start debugging? Or do you use some other method altogether?
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I have never had that problem, or heard of it. You might want to search google. Sounds like a strange bug to me.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Yup, strange indeed.
Google didn't give me anything useful, but then again I'm not the best at selecting search terms.
Are you using SQL Express?
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Yes I am using SQL Express, and vs 2005. Are you using VS 2003? what is the error message you are recieving?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|