Click here to Skip to main content
15,894,539 members
Home / Discussions / C#
   

C#

 
QuestionForm data printing problem Pin
Mark F.2-Apr-10 3:54
Mark F.2-Apr-10 3:54 
AnswerRe: Form data printing problem Pin
Luc Pattyn2-Apr-10 3:59
sitebuilderLuc Pattyn2-Apr-10 3:59 
GeneralRe: Form data printing problem Pin
Mark F.2-Apr-10 4:11
Mark F.2-Apr-10 4:11 
GeneralRe: Form data printing problem Pin
Luc Pattyn2-Apr-10 4:20
sitebuilderLuc Pattyn2-Apr-10 4:20 
GeneralRe: Form data printing problem Pin
Mark F.2-Apr-10 4:26
Mark F.2-Apr-10 4:26 
Questionvscrollbar Pin
v17.poornima2-Apr-10 3:17
v17.poornima2-Apr-10 3:17 
AnswerRe: vscrollbar Pin
Ravi Bhavnani2-Apr-10 7:06
professionalRavi Bhavnani2-Apr-10 7:06 
QuestionSQL Data Base Update - Best approach nested implementation Pin
boreland2-Apr-10 2:26
boreland2-Apr-10 2:26 
I'm new to sql and would appreciate some help on the best way to structure the following type of operation. I have a db containing stock symbols. I'm retrieving each symbol, calculating a series of moving averages and updating the symbol table with the calculated values for each row in the symbol table. The way I have things structured below takes "for ever" to run through? Utlimately there will be a 1000 or more symbols in the db. Any help would be appreciated!

try
            {
                SQLiteConnection conn = new SQLiteConnection(Constants.ConnectionString);
                if (conn.State == ConnectionState.Closed)
                    conn.Open(); 

                string CommandText = "SELECT symbol FROM master;";
                SQLiteDataAdapter  dataAdapter = new SQLiteDataAdapter(CommandText, conn); 
                 
                DataTable dt = new DataTable();
                dataAdapter.Fill(dt);
                DataTable symdt = new DataTable(); 

                IMovingAverage ma20 = new SimpleMovingAverage(20);
                IMovingAverage ma50 = new SimpleMovingAverage(50);
                IMovingAverage ma200 = new SimpleMovingAverage(200); 

                //Sequencially process each symbol in the database.

                foreach (DataRow r in dt.Rows)
                {   
                    //Now get data associated with each symbol and process              
      
                    CommandText = "SELECT * FROM " + r["Symbol"].ToString() + ";";
                    SQLiteDataAdapter symdataAdapter = new SQLiteDataAdapter(CommandText, conn);
                    
                    symdataAdapter.Fill(symdt);
                    int count = 0;

                    //Sequencially process each row in the symbol table.

                    foreach (DataRow symr in symdt.Rows)
                    {  
                        //20 Period Simple Moving Average  
                        if (symdt.Rows.Count >= 20)
                        { 
                            ma20.AddSample(Convert.ToSingle(symdt.Rows[count]["Close"]));
                            symdt.Rows[count]["MA20"] = ma20.Average;  
                        }
                        //50 Period Simple Moving Average 
                        if (symdt.Rows.Count >= 50)
                        { 
                            ma50.AddSample(Convert.ToSingle(symdt.Rows[count]["Close"]));
                            symdt.Rows[count]["MA50"] = ma50.Average; 
                             
                        }
                        //200 Period Simple Moving Average 
                        if (symdt.Rows.Count >= 200)
                        { 
                            ma200.AddSample(Convert.ToSingle(symdt.Rows[count]["Close"]));
                            symdt.Rows[count]["MA200"] = ma200.Average; 
                        } 
                        ++count;
                    }
                   
                    SQLiteCommandBuilder mySqlCommandBuilder = new SQLiteCommandBuilder(symdataAdapter);
                    symdataAdapter.Update(symdt);
                    
                    symdt.Clear();
                    symdataAdapter.Dispose();

                    //Clear circular buffers
                    ma20.ClearSamples();
                    ma200.ClearSamples();
                    ma50.ClearSamples(); 
                }
                dt.Clear();
                dataAdapter.Dispose();
                
                conn.Close();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }  

AnswerRe: SQL Data Base Update - Best approach nested implementation Pin
Not Active2-Apr-10 2:40
mentorNot Active2-Apr-10 2:40 
GeneralRe: SQL Data Base Update - Best approach nested implementation Pin
boreland2-Apr-10 4:59
boreland2-Apr-10 4:59 
GeneralRe: SQL Data Base Update - Best approach nested implementation Pin
Not Active2-Apr-10 5:48
mentorNot Active2-Apr-10 5:48 
AnswerRe: SQL Data Base Update - Best approach nested implementation Pin
boreland2-Apr-10 5:00
boreland2-Apr-10 5:00 
AnswerRe: SQL Data Base Update - Best approach nested implementation Pin
Rob Graham2-Apr-10 8:18
Rob Graham2-Apr-10 8:18 
QuestionRectangle.Intersect() or Rectangle.Contains() ? Pin
venomation2-Apr-10 1:57
venomation2-Apr-10 1:57 
AnswerRe: Rectangle.Intersect() or Rectangle.Contains() ? Pin
Luc Pattyn2-Apr-10 2:24
sitebuilderLuc Pattyn2-Apr-10 2:24 
QuestionRedirecting an output stream Pin
Lutosław2-Apr-10 1:24
Lutosław2-Apr-10 1:24 
AnswerRe: Redirecting an output stream Pin
Luc Pattyn2-Apr-10 2:33
sitebuilderLuc Pattyn2-Apr-10 2:33 
GeneralRe: Redirecting an output stream Pin
Lutosław2-Apr-10 3:50
Lutosław2-Apr-10 3:50 
GeneralRe: Redirecting an output stream Pin
Luc Pattyn2-Apr-10 3:54
sitebuilderLuc Pattyn2-Apr-10 3:54 
GeneralRe: Redirecting an output stream Pin
Lutosław2-Apr-10 4:39
Lutosław2-Apr-10 4:39 
AnswerRe: Redirecting an output stream Pin
PIEBALDconsult2-Apr-10 4:06
mvePIEBALDconsult2-Apr-10 4:06 
GeneralRe: Redirecting an output stream Pin
Lutosław2-Apr-10 4:40
Lutosław2-Apr-10 4:40 
News[Solved!] Redirecting an output stream Pin
Lutosław2-Apr-10 4:44
Lutosław2-Apr-10 4:44 
GeneralRe: [Solved!] Redirecting an output stream Pin
Luc Pattyn2-Apr-10 4:49
sitebuilderLuc Pattyn2-Apr-10 4:49 
GeneralRe: [Solved!] Redirecting an output stream Pin
Lutosław2-Apr-10 5:21
Lutosław2-Apr-10 5:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.