I have added a Microsoft's SQL Server file to my project and I am running an SqlCommand
to insert my data into the file. I am using System.Data.SqlClient;
. The following code is how I add data to my file. After my program finished running then I go to the Data Explorer in my project and ask to Show Table Data of HistQuote
and nothing show up. Could anyone advice on how I can verify that my INSERT
statement is working.
using (SqlConnection connection = new SqlConnection(Settings.Default.StorageConnectionString))
{
connection.Open();
for (int intCurrentQuote = 0; intCurrentQuote < this.clbStockSelect.CheckedItems.Count; ++intCurrentQuote)
{
for (int intCurrentDate = 0; intCurrentDate < Quotes[intCurrentQuote].HistStockDate.Count; ++intCurrentDate)
{
string strInsert = "INSERT INTO [HistQuote] ";
string strColumns = "(Symbol, [Date], [Open], High, Low, Volume, Adj_Close, [Close]) ";
string strValues = "VALUES (@Symbol, @Date, @Open, @High, @Low, @Volume, @Adj_Close, @Close)";
using (SqlCommand sqlCommand = new SqlCommand(strInsert + strColumns + strValues, connection))
{
sqlCommand.Parameters.Clear();
sqlCommand.Parameters.Add(new SqlParameter("@Symbol", SqlDbType.NChar));
sqlCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
sqlCommand.Parameters.Add(new SqlParameter("@Open", SqlDbType.Real));
sqlCommand.Parameters.Add(new SqlParameter("@High", SqlDbType.Real));
sqlCommand.Parameters.Add(new SqlParameter("@Low", SqlDbType.Real));
sqlCommand.Parameters.Add(new SqlParameter("@Close", SqlDbType.Real));
sqlCommand.Parameters.Add(new SqlParameter("@Volume", SqlDbType.Real));
sqlCommand.Parameters.Add(new SqlParameter("@Adj_Close", SqlDbType.Real));
sqlCommand.Parameters["@Symbol"].Size = 10;
sqlCommand.Prepare();
sqlCommand.Parameters["@Symbol"].Value = this.Quotes[intCurrentQuote].HistSymbol;
sqlCommand.Parameters["@Date"].Value = this.Quotes[intCurrentQuote].HistStockDate[intCurrentDate];
sqlCommand.Parameters["@Open"].Value = this.Quotes[intCurrentQuote].HistOpen[intCurrentDate];
sqlCommand.Parameters["@High"].Value = this.Quotes[intCurrentQuote].HistHigh[intCurrentDate];
sqlCommand.Parameters["@Low"].Value = this.Quotes[intCurrentQuote].HistLow[intCurrentDate];
sqlCommand.Parameters["@Close"].Value = this.Quotes[intCurrentQuote].HistClose[intCurrentDate];
sqlCommand.Parameters["@Volume"].Value = this.Quotes[intCurrentQuote].HistVolume[intCurrentDate];
sqlCommand.Parameters["@Adj_Close"].Value = this.Quotes[intCurrentQuote].HistAdjClose[intCurrentDate];
sqlCommand.ExecuteNonQuery();
sqlCommand.Parameters.Clear();
}
}
}
connection.Close();
}
Would something like this possibly work?