Click here to Skip to main content
15,915,770 members
Home / Discussions / C#
   

C#

 
GeneralRe: I am sorry if I am asking an abstract question; but I have a multithreaded question Pin
half-life6-Feb-08 8:53
half-life6-Feb-08 8:53 
GeneralEmbedding a control inside a toolbar Pin
sabrown1006-Feb-08 7:28
sabrown1006-Feb-08 7:28 
QuestionProgramattically creating new threads Pin
miles.smith6-Feb-08 7:04
miles.smith6-Feb-08 7:04 
GeneralRe: Programattically creating new threads Pin
led mike6-Feb-08 7:22
led mike6-Feb-08 7:22 
GeneralRe: Programattically creating new threads Pin
miles.smith6-Feb-08 7:25
miles.smith6-Feb-08 7:25 
GeneralRe: Programattically creating new threads Pin
Ennis Ray Lynch, Jr.6-Feb-08 7:32
Ennis Ray Lynch, Jr.6-Feb-08 7:32 
GeneralRe: Programattically creating new threads Pin
led mike6-Feb-08 7:41
led mike6-Feb-08 7:41 
GeneralRe: Programattically creating new threads Pin
miles.smith6-Feb-08 7:43
miles.smith6-Feb-08 7:43 
GeneralRe: Programattically creating new threads Pin
led mike6-Feb-08 8:28
led mike6-Feb-08 8:28 
QuestionImplementing IExceptionHandler from Exception Handling Application Block (EMAB) without Configuration file? Pin
kumar.bs6-Feb-08 7:03
kumar.bs6-Feb-08 7:03 
GeneralC# Console to C# forms Pin
jimmy2shoes6-Feb-08 6:51
jimmy2shoes6-Feb-08 6:51 
GeneralRe: C# Console to C# forms Pin
Dan Neely6-Feb-08 7:17
Dan Neely6-Feb-08 7:17 
GeneralRe: C# Console to C# forms Pin
jimmy2shoes6-Feb-08 7:23
jimmy2shoes6-Feb-08 7:23 
GeneralRe: C# Console to C# forms Pin
Dan Neely6-Feb-08 8:29
Dan Neely6-Feb-08 8:29 
GeneralLed UI CONTROL Pin
half-life6-Feb-08 5:44
half-life6-Feb-08 5:44 
GeneralRe: Led UI CONTROL Pin
led mike6-Feb-08 7:28
led mike6-Feb-08 7:28 
GeneralRe: Led UI CONTROL Pin
Brady Kelly6-Feb-08 7:45
Brady Kelly6-Feb-08 7:45 
GeneralRe: Led UI CONTROL Pin
half-life6-Feb-08 8:22
half-life6-Feb-08 8:22 
GeneralRe: Led UI CONTROL Pin
half-life6-Feb-08 8:27
half-life6-Feb-08 8:27 
GeneralRe: Led UI CONTROL Pin
Ravi Bhavnani6-Feb-08 9:06
professionalRavi Bhavnani6-Feb-08 9:06 
GeneralRe: Led UI CONTROL Pin
half-life6-Feb-08 9:15
half-life6-Feb-08 9:15 
Generalexcel factory update Pin
arkiboys6-Feb-08 5:31
arkiboys6-Feb-08 5:31 
GeneralRe: excel factory update Pin
Jimmanuel6-Feb-08 7:39
Jimmanuel6-Feb-08 7:39 
GeneralRe: excel factory update Pin
arkiboys6-Feb-08 21:22
arkiboys6-Feb-08 21:22 
This is my exact code.
can you see where to change it to the way you suggeste please?
I am looping through a datagridview control and for each record in the control I am updating the excel sheet.


try
{
//get prices for securities...
int intSecurity_IDColumn = dgvSecurityPricing.Columns["Security_ID"].Index;
int intSecurity_NameColumn = dgvSecurityPricing.Columns["Security_Name"].Index;
int intBid_Price_Best_LatestColumn = dgvSecurityPricing.Columns["Bid_Price_Best_Latest"].Index;
int intAsk_Price_Best_LatestColumn = dgvSecurityPricing.Columns["Ask_Price_Best_Latest"].Index;

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MarketAnalytics\YieldsSpreads\YieldsSpreads.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

foreach (DataGridViewRow row in dgvSecurityPricing.Rows)
{
string strSecurity_ID = row.Cells[intSecurity_IDColumn].Value.ToString();
string strSecurity_Name = row.Cells[intSecurity_NameColumn].Value.ToString();
string strBid_Price_Best_Latest = row.Cells[intBid_Price_Best_LatestColumn].Value.ToString();
string strAsk_Price_Best_Latest = row.Cells[intAsk_Price_Best_LatestColumn].Value.ToString();

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");

using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;

using (DbCommand command = connection.CreateCommand())
{
//only send prices if there is one...
string strSQL = "";

if (strBid_Price_Best_Latest.Length > 0 && strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length > 0 && strAsk_Price_Best_Latest.Length == 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length == 0 && strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length == 0 && strAsk_Price_Best_Latest.Length == 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}

//command.CommandText = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
command.CommandText = strSQL;
//Console.WriteLine(strSQL);
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
GeneralRe: excel factory update [modified] Pin
Jimmanuel7-Feb-08 3:48
Jimmanuel7-Feb-08 3:48 

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.