|
it looks like you have the second for loop inside the first, that is not what you want to do.
Here is some pseudocode to assist you
foreach column in the data grid that contains header information
{
r[1,colIndex]=column text
}
foreach row in the data grid that contains information to write to database
{
r[row+1,1]=first column of the specified row will write its data to the excel spreadsheet
r[row+1,2]=second column of the specified row will write its data to the excel spreadsheet
}//this will increment for every row in the data grid.
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 homepage Oracle Studios[ ^]
|
|
|
|
|
Thanks a lot, this was very helpful.
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
I have this code that will export to a CSV file. Maybe it will help.
StreamWriter sw = new StreamWriter(@"C:\EPORT\ExportFile_" + DateTime.Today.ToString("ddMMyyyy") + ".csv", false);
DataTable dt = m_dtMobEmail;
int iColCount = dt.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(@"""{0}""", dt.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
foreach (DataRow dr in dt.Rows)
{
if (dr["Exported"].ToString() == "0")
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
sw.Write(@"""{0}""", dr[i].ToString());
}
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
}
}
sw.Close();
|
|
|
|
|
I was sure I posted this message earlier... Although it didn't show under my posts... *Shrug*
Also, there's no "Graphics" section, and it is really C# Code...
Anyways, I was chatting to a few people who refuse to use GDI+ due to it's lack of "Flashy Effects" - Tinting, Lighting, Etc.
So, I ask you now - Is it possible?
Maybe a cool fiery effect (Fantastic Flame Screensaver, Anyone?)
Post your suggestions / Code Snippets showing off your "Special Effects"
Be Creative people
- Reelix
|
|
|
|
|
If you are interested in finding out how to do flashy effects, you should think about checking out Paint.Net - its an open source alternative to PhotoShop, which as far as I am aware, is programmed with GDI+ and can produce some quite nice stuff!
Chris
|
|
|
|
|
Hi,
Any one have to help me in this regard.. please........... since new to c#.net.
thanks in advance
I have a "logging.exe.config" file in different location,
I have to
1. Load The File,
2. Read The file
3. Modify particular values.
4. Update and Save The file in the same location.
My "Logger.exe.config" looks something like this
i need to set the values like enabled,logging values to true/false,.............
Please anyone help me...............
<?xml version="1.0" encoding="utf-8"?><br />
<configuration><br />
<configSections><br />
<section name="WriterTrace2Config" type="Configuration.ConfigSectionReader, Infrastructure.Logging.Helper" /><br />
<section name="TextReaderLogConfig" type="Configuration.ConfigSectionReader, Infrastructure.Logging.Helper" /><br />
</configSections><br />
--------------<br />
---------------<br />
<Listeners><br />
<ListenerInfo Type="Infrastructure.Logging.WriterTraceListener2,Infrastructure.Logging.Listeners.WriterListener2" Enabled="true" Name="TextLogger2" /><br />
<ListenerInfo Type="Infrastructure.Logging.TextReaderLog,Infrastructure.Logging.Listeners.TextReaderLogListener" Enabled="true" Name="TextReaderLog" /><br />
</Listeners><br />
--------------<br />
---------------<br />
<WriterTraceListener2Config type="Infrastructure.Logging.WriterTraceListener2Config,Infrastructure.Logging.Library.ConfigurationManager" xmlns="http://Infrastructure/Configuration.xsd" Name="WriterLog" Filtering="false"><br />
<Storage Location="C:\Logs\WriterLog" LogFileNamePrefix="TraceLog" Logging="false" SubDirectoryNamePrefix="Writer"><br />
<HeaderText>Logging Service Helper</HeaderText><br />
</Storage><br />
</WriterTraceListener2Config><br />
<TextReaderLogListenerConfig type="Infrastructure.Logging.ListenerConfig.TextReaderLogListenerConfig, Infrastructure.Logging.Listeners.TextReaderLogListener" xmlns="http://Infrastructure/Configuration.xsd" Name="ReaderLog" Filtering="true"><br />
<Storage Location="c:\Logs\TextReaderLog" SubDirectoryNamePrefix="TextReaderLog"><br />
<HeaderText>Logging Service Helper</HeaderText><br />
</Storage><br />
</KTTextRunLogListenerConfig><br />
</configuration>
BhuMan
|
|
|
|
|
Using System.IO;
// Read The File
string thePath = "";//Path to the XML Here
StreamReader sr = new StreamReader(thePath);
string tmp = sr.ReadToEnd();
tmp = tmp.Replace("Original Value", "New Value");
sr.Close();
// Write the file
StreamWriter sw = new StreamWriter(thePath);
sw.WriteLine(tmp);
sw.Flush();
sw.Close():
Hope that helps
|
|
|
|
|
|
hi, i'm posting 'cause i have a problem i can't manage to solve...
i have a page with a row of DropDownLists, and what i want to do is this: when the user selects a value from one of the dropdowns , a new one is created under the selected, with the same values of the previous one, except for the selected one.
i know i have to write a function in c# called from OnSelectedIndexChange, but i can't understand how to create the new ddl from the code..
can anyone one help me or suggest a better way to do that?
thanks anyway, and sorry for the poor english..
bye
Kontax
|
|
|
|
|
DropDownList1_OnSelectedIndexChange
{
DropDownList2.Visible = true;
}
Crude I know, but it works
|
|
|
|
|
thanks anyway, but i think i explaned it in a wrong way...
i dont know previously the number of DDL the user needs, so i cant create them before.
suggestions?
|
|
|
|
|
private System.Windows.Forms.ListBox listBox1;
private void button1_Click(object sender, EventArgs e)
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(50, 50);
this.listBox1.Items.Add("Testing");
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.l1_SelectedIndexChanged);
this.Controls.Add(listBox1);
this.ResumeLayout();
}
private void l1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("It Works!");
}
Im not proud of it, but it works...
Might need some heavy modification...
|
|
|
|
|
Thanks for the answer,
it's just some days i'm working with c# so i can't understand what you wrote, anyway thank you another time, i'll try to understand and use it!
byee
|
|
|
|
|
Well, you didn't know how many ddl you will need so you can't create them in design time. What he showed you is that you can dynamically create them once you know that you need a ddl, during the post back.
|
|
|
|
|
hi..
I can't manage to work with that code...
It says that i need the System.Windows.Forms namespace. But if i include it with "using" it doesn't works, cause he can't find the system.windows namespace.
i tried to download System.Windows.Forms.dll and put it in C:\windows\assembly but nothing changed..suggestions?how can i include it?
|
|
|
|
|
hello
in my c# application and when i use the extender desktop, the open dialog box appear in the other screen of my application any idea???
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
Hey Guys,
Have a look at this piece of code...
public void checkPollingTimesFromHash()
{
foreach (object TerminalID in pollTimesHash)
{
txtLog.AppendText("****** " + TerminalID + "\r\n");
foreach (object PollTime in TerminalID)
{
txtLog.AppendText(PollTime + "\r\n");
}
}
}
pollTimesHash is a hash table with an object (its a number - terminal id, its of type object cuz i assign these in a foreach obj in arraylist) as its key and an arraylist object in the value. The objects inside the arraylist are of type TimeSpan
in the block above im trying to iterate through each terminals polling times. but my IDE moans "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'"
any ideas on how i can get my desired result?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Well, the compiler's "moaning" isn't really moaning at all: The foreach statement depends on the implementation of the IEnumerable interface.
Imagine the foreach statement wasn't there in c#, how would you use an ordinary for-loop to iterate through TerminalID to get each member? You'd need to cast it to a type you can actually iterate through first.
The compiler cannot guess the object type for TerminalID: You need to cast it to the type implementing IEnumerable interface (which most collection type classes do).
Standards are great! Everybody should have one!
|
|
|
|
|
yeah i get all that...
just not how to do what im supposed to
how would i go about casing to the type implementing IEnumerable interface?
ive just changed the block to this...
public void checkPollingTimesFromHash()
{
foreach (object TerminalID in pollTimesHash)
{
txtLog.AppendText("****** " + TerminalID + "\r\n");
foreach (object PollTime in pollTimesHash[TerminalID])
{
txtLog.AppendText(PollTime + "\r\n");
}
}
}
it makes more sence to me this way
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
public void checkPollingTimesFromHash()
{
foreach (object TerminalID in pollTimesHash)
{
IEnumerable pollTimes = (IEnumerable)pollTimesHash[TerminalID];
txtLog.AppendText("****** " + TerminalID + "\r\n");
foreach (object PollTime in pollTimes )
{
txtLog.AppendText(PollTime + "\r\n");
}
}
}
|
|
|
|
|
thanx
i get a nullReferenceExeption tho...pollTimes = null
any idea why? pollTimesHash defenitly has values in it
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Im pretty sure the problem here is in the way you're enumerating the hashtable.
<br />
foreach(object o in myHashTable)
In this case, the object "o" is a DictionaryEntry , not the Key nor the value from the hashtable.
Change this to:
foreach(DictionaryEntry de in myHashTable)
and you'll get intellisense help on "de" - where you'll see it has a property Key and a property Value .
Now, go from there... cast the Value to an IEnumerable (or better still, if you know what type of object is stored in the value cast it to that).
|
|
|
|
|
sweet
ok now i have this...
public void checkPollingTimesFromHash()
{
foreach (DictionaryEntry de in pollTimesHash)
{
int terminalID = Int32.Parse(de.Key.ToString());
txtLog.AppendText("****** " + terminalID.ToString() + "\r\n");
ArrayList pollTimes = (ArrayList)pollTimesHash[terminalID];
foreach (object obj in pollTimes)
{
txtLog.AppendText(obj.ToString() + "\r\n");
}
}
}
but im still getting nullReference on pollTimes.
while debugging i can see terminalID = 1, and pollTimesHash Count = 2. So there definitely is data in there
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hashtable pollTimesHash = new Hashtable();
Random rand = new Random();
int hashCount = rand.Next(10, 20);
for (int i = 0; i < hashCount; i++)
{
ArrayList al = new ArrayList();
int alCount = rand.Next(10,20);
for(int j = 0; j<alCount; j++)
{
al.Add(new TimeSpan(rand.Next()));
}
pollTimesHash.Add(i, al);
}
StringBuilder sb = new StringBuilder();
foreach (DictionaryEntry item in pollTimesHash)
{
sb.AppendLine(string.Format("{0} ({1} count)", item.Key.ToString(), ((ArrayList)item.Value).Count.ToString()));
foreach (TimeSpan pollTime in (ArrayList)item.Value)
{
sb.AppendLine(pollTime.ToString());
}
}
Console.Write(sb.ToString());
|
|
|
|
|
Hello your code is wrong you need solution add me hussaingreat2@hotmail.com
i am certified in C# programming ok Br
but i need some 10g codes because i want to break linux server i have full linux source code
Hussaingreat
|
|
|
|