Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
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 
Generala little more constructive criticism . . . Pin
Jimmanuel7-Feb-08 7:48
Jimmanuel7-Feb-08 7:48 
GeneralRe: a little more constructive criticism . . . Pin
arkiboys7-Feb-08 22:14
arkiboys7-Feb-08 22:14 
GeneralOracle too slow in .Net Pin
El'Cachubrey6-Feb-08 3:58
El'Cachubrey6-Feb-08 3:58 
JokeRe: Oracle too slow in .Net Pin
Not Active6-Feb-08 4:03
mentorNot Active6-Feb-08 4:03 
AnswerRe: Oracle too slow in .Net Pin
Guffa6-Feb-08 4:56
Guffa6-Feb-08 4:56 
GeneralRe: Oracle too slow in .Net Pin
El'Cachubrey6-Feb-08 7:55
El'Cachubrey6-Feb-08 7:55 
GeneralRe: Oracle too slow in .Net Pin
Guffa6-Feb-08 8:17
Guffa6-Feb-08 8:17 
GeneralRe: Oracle too slow in .Net Pin
Ennis Ray Lynch, Jr.6-Feb-08 7:34
Ennis Ray Lynch, Jr.6-Feb-08 7:34 
GeneralRe: Oracle too slow in .Net Pin
El'Cachubrey6-Feb-08 7:50
El'Cachubrey6-Feb-08 7:50 
AnswerRe: Oracle too slow in .Net Pin
Guffa6-Feb-08 8:10
Guffa6-Feb-08 8:10 
GeneralHtml to Pdf Pin
marky7776-Feb-08 3:46
marky7776-Feb-08 3:46 
GeneralRe: Html to Pdf Pin
sabrown1006-Feb-08 7:30
sabrown1006-Feb-08 7:30 
GeneralFTP check for existing files Pin
Dreamzor6-Feb-08 3:44
Dreamzor6-Feb-08 3:44 
GeneralRe: FTP check for existing files Pin
Not Active6-Feb-08 4:01
mentorNot Active6-Feb-08 4:01 
GeneralRe: FTP check for existing files Pin
Dreamzor6-Feb-08 4:21
Dreamzor6-Feb-08 4:21 
GeneralRe: FTP check for existing files Pin
Not Active6-Feb-08 4:35
mentorNot Active6-Feb-08 4:35 

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.