Click here to Skip to main content
15,391,980 members
Home / Discussions / WPF


QuestionTimeline Thumb Style Pin
Kevin Marois18-Apr-17 6:19
professionalKevin Marois18-Apr-17 6:19 
QuestionInterpret an Error Pin
Mycroft Holmes28-Mar-17 22:31
professionalMycroft Holmes28-Mar-17 22:31 
AnswerRe: Interpret an Error - Resolved Pin
Mycroft Holmes28-Mar-17 22:51
professionalMycroft Holmes28-Mar-17 22:51 
QuestionBinding Delay Pin
Mycroft Holmes20-Mar-17 17:14
professionalMycroft Holmes20-Mar-17 17:14 
QuestionFormating DataGrid cell depending on content of multiple cells Pin
kilauea-de5-Mar-17 9:17
Memberkilauea-de5-Mar-17 9:17 
AnswerRe: Formating DataGrid cell depending on content of multiple cells Pin
Richard Deeming5-Mar-17 23:57
mveRichard Deeming5-Mar-17 23:57 
GeneralRe: Formating DataGrid cell depending on content of multiple cells Pin
kilauea-de15-Mar-17 2:54
Memberkilauea-de15-Mar-17 2:54 
QuestionHow can I set my SQL stored procedure variables through WPF textboxs? Pin
Magerager3-Mar-17 4:03
MemberMagerager3-Mar-17 4:03 
I feel quite defeated and overwhelmed at present. Apologies if this is done incorrectly. Any assistance would be warmly welcomed.

I'm writing a program in WPF, using c#, which should collect inputs via relevant textbox fields. These inputs should filter through to my sql command parameters, where I can then run the stored procedure. Then the info should populate back into a Datagrid in WPF mainwindow.

Basically, searching through historical stock pricing, returning all info between date, price, volume, etc, based on whichever values the user selects.

My SQL stored procedure returns expected values. The only way I can get my program to return the same values is to hardcode each input. I know I am missing the link between getting the values from each textbox into the SQL command parameters, but I'm at a loss as to how to do this. I think I need to set an event in my "mainwindow.xaml.cs" but I just cannot work out the right syntax...

<pre>namespace MBM3._0
    public partial class MainWindow : Window
        //StockValues _StockContext = new StockValues();
        StockValues src = new StockValues();

        public MainWindow()
            Loaded += MainWindow_Loaded;
            this.DataContext = src;

        public void MainWindow_Loaded(object sender, RoutedEventArgs e)
            textBoxStockSymbol.Text = "AEA";
            textBoxDateFrom.Text = "2000-01-03";
            textBoxDateTo.Text = "2010-02-08";
            textBoxSPOpenFrom.Text = "0";
            textBoxSPOpenTo.Text = "50";
            textBoxSPCloseFrom.Text = "50";
            textBoxSPCloseTo.Text = "50";
            textBoxSPACloseFrom.Text = "50";
            textBoxSPACTo.Text = "50";
            textBoxSPHighFrom.Text = "50";
            textBoxSPHighTo.Text = "50";
            textBoxSPLowFrom.Text = "50";
            textBoxSPLowTo.Text = "50";
            textBoxSVolumeFrom.Text = "50";
            textBoxSVolumeTo.Text = "50";                                           

        private void dataGrid_Loaded(object sender, RoutedEventArgs e)


        private void buttonFind_Click(object sender, RoutedEventArgs e)
                DataTable MSQ = DataLayer.Stock.MSQ("WPFDemo App");
                dataGrid.ItemsSource = MSQ.DefaultView;
            catch (SqlException sqlex)
                MessageBox.Show("Error: " + sqlex.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Warning);

        private void textBoxStockSymbol_TextChanged(object sender, TextChangedEventArgs e)


And Stock Layer
<pre>namespace DataLayer
    public class Stock
        /// <summary>
        /// Returns query to datatable, which can be loaded into Datagrid.
        /// </summary>
        /// <param name="appName"></param>
        /// <returns></returns>
        public static DataTable MSQ(string appName)
            DataTable table1 = new DataTable();
            SqlDataAdapter da1 = new SqlDataAdapter();
            StockValues sv = new StockValues();

            using (SqlConnection conn = Database.GetSqlConnection())
                //using (SqlCommand cmd = conn.CreateCommand())
                SqlCommand cmd = new SqlCommand("SELECT date, stock_symbol, stock_price_open, stock_price_close, stock_price_lo, stock_price_high, stock_price_adj_close, stock_volume FROM NYSE WHERE date BETWEEN @date_from AND @date_to AND stock_symbol LIKE @stock_symbol AND stock_price_open BETWEEN @stock_price_open_from AND @stock_price_open_to AND stock_price_close BETWEEN @stock_price_close_from AND @stock_price_adj_close_to AND stock_price_lo BETWEEN @stock_price_lo_from AND @stock_price_lo_to AND stock_price_high BETWEEN @stock_price_high_from AND @stock_price_high_to AND stock_price_adj_close BETWEEN @stock_price_adj_close_from AND @stock_price_adj_close_to AND stock_volume BETWEEN @stock_volume_from AND @stock_volume_to", conn);
                cmd.Parameters.Add(new SqlParameter("date_from", System.Data.SqlDbType.Date));
                cmd.Parameters.Add(new SqlParameter("date_to", System.Data.SqlDbType.Date));
                cmd.Parameters.Add(new SqlParameter("stock_symbol", System.Data.SqlDbType.VarChar));
                cmd.Parameters.Add(new SqlParameter("stock_price_open_from", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_open_to", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_close_from", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_close_to", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_lo_from", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_lo_to", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_high_from", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_high_to", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_adj_close_from", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_price_adj_close_to", System.Data.SqlDbType.Float));
                cmd.Parameters.Add(new SqlParameter("stock_volume_from", System.Data.SqlDbType.Int));
                cmd.Parameters.Add(new SqlParameter("stock_volume_to", System.Data.SqlDbType.Int));
                cmd.Parameters["date_from"].Value = "2000-01-03";
                cmd.Parameters["date_to"].Value = "2010-02-08";
                cmd.Parameters["stock_symbol"].Value = "%";
                cmd.Parameters["stock_price_open_from"].Value = "50";
                cmd.Parameters["stock_price_open_to"].Value = "50";
                cmd.Parameters["stock_price_close_from"].Value = "0";
                cmd.Parameters["stock_price_close_to"].Value = "500";
                cmd.Parameters["stock_price_lo_from"].Value = "0";
                cmd.Parameters["stock_price_lo_to"].Value = "500";
                cmd.Parameters["stock_price_high_from"].Value = "0";
                cmd.Parameters["stock_price_high_to"].Value = "500";
                cmd.Parameters["stock_price_adj_close_from"].Value = "0";
                cmd.Parameters["stock_price_adj_close_to"].Value = "500";
                cmd.Parameters["stock_volume_from"].Value = "0";
                cmd.Parameters["stock_volume_to"].Value = "1000000000";
                //SqlCommand cmd = new SqlCommand("EXEC MasterStockQuery1 @date_from, @,'%',50,50,0,500,0,500,0,500,0,500,0,1000000000", conn);
                //cmd.CommandText = @"MasterStockQuery1";
                //cmd.CommandType = System.Data.CommandType.StoredProcedure;
                //SqlParameter p1 = new SqlParameter("@date_from", SqlDbType.Date);
                //p1.Value = date_from;
                //SqlParameter p2 = new SqlParameter("@date_to", SqlDbType.Date);
                //p2.Value = sv.date_to;
                //SqlParameter p3 = new SqlParameter("@stock_symbol", SqlDbType.VarChar);
                //p3.Value = sv.stock_symbol;
                //SqlParameter p4 = new SqlParameter("@stock_price_open_from", SqlDbType.Float);
                //p4.Value = sv.stock_price_open_from;
                //SqlParameter p5 = new SqlParameter("@stock_price_open_to", SqlDbType.Float);
                //p5.Value = sv.stock_price_open_to;
                //SqlParameter p6 = new SqlParameter("@stock_price_close_from", SqlDbType.Float);
                //p6.Value = sv.stock_price_close_from;
                //SqlParameter p7 = new SqlParameter("@stock_price_close_to", SqlDbType.Float);
                //p7.Value = sv.stock_price_close_to;
                //SqlParameter p8 = new SqlParameter("@stock_price_lo_from", SqlDbType.Float);
                //p8.Value = sv.stock_price_lo_from;
                //SqlParameter p9 = new SqlParameter("@stock_price_lo_to", SqlDbType.Float);
                //p9.Value = sv.stock_price_lo_to;
                //SqlParameter p10 = new SqlParameter("@stock_price_high_from", SqlDbType.Float);
                //p10.Value = sv.stock_price_high_from;
                //SqlParameter p11 = new SqlParameter("@stock_price_high_to", SqlDbType.Float);
                //p11.Value = sv.stock_price_high_to;
                //SqlParameter p12 = new SqlParameter("@stock_price_adj_close_from", SqlDbType.Float);
                //p12.Value = sv.stock_price_adj_close_from;
                //SqlParameter p13 = new SqlParameter("@stock_price_adj_close_to", SqlDbType.Float);
                //p13.Value = sv.stock_price_adj_close_to;
                //SqlParameter p14 = new SqlParameter("@stock_volume_from", SqlDbType.Int);
                //p14.Value = sv.stock_volume_from;
                //SqlParameter p15 = new SqlParameter("@stock_volume_to", SqlDbType.Int);
                //p15.Value = sv.stock_volume_to;

                da1 = new SqlDataAdapter(cmd);
                return table1;

public class StockValues
    public DateTime date_from { get; set; }
    public DateTime date_to { get; set; }
    public string stock_symbol { get; set; }
    public float stock_price_open_from { get; set; }
    public float stock_price_open_to { get; set; }
    public float stock_price_close_from { get; set; }
    public float stock_price_close_to { get; set; }
    public float stock_price_lo_from { get; set; }
    public float stock_price_lo_to { get; set; }
    public float stock_price_high_from { get; set; }
    public float stock_price_high_to { get; set; }
    public float stock_price_adj_close_from { get; set; }
    public float stock_price_adj_close_to { get; set; }
    public int stock_volume_from { get; set; }
    public int stock_volume_to { get; set; }

AnswerRe: How can I set my SQL stored procedure variables through WPF textboxs? Pin
Richard Deeming3-Mar-17 4:25
mveRichard Deeming3-Mar-17 4:25 
GeneralRe: How can I set my SQL stored procedure variables through WPF textboxs? Pin
Magerager3-Mar-17 12:29
MemberMagerager3-Mar-17 12:29 
QuestionJavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Kevin Marois2-Mar-17 10:35
professionalKevin Marois2-Mar-17 10:35 
SuggestionRe: JavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Richard Deeming2-Mar-17 10:49
mveRichard Deeming2-Mar-17 10:49 
GeneralRe: JavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Kevin Marois2-Mar-17 10:51
professionalKevin Marois2-Mar-17 10:51 
GeneralRe: JavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Kevin Marois2-Mar-17 10:52
professionalKevin Marois2-Mar-17 10:52 
GeneralRe: JavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Richard Deeming3-Mar-17 2:32
mveRichard Deeming3-Mar-17 2:32 
QuestionJQuery Not Found Pin
Kevin Marois2-Mar-17 8:25
professionalKevin Marois2-Mar-17 8:25 
AnswerRe: JQuery Not Found Pin
Sander Rossel2-Mar-17 8:37
professionalSander Rossel2-Mar-17 8:37 
GeneralRe: JQuery Not Found Pin
Kevin Marois2-Mar-17 10:02
professionalKevin Marois2-Mar-17 10:02 
GeneralRe: JQuery Not Found Pin
Sander Rossel2-Mar-17 10:16
professionalSander Rossel2-Mar-17 10:16 
GeneralRe: JQuery Not Found Pin
Kevin Marois2-Mar-17 10:29
professionalKevin Marois2-Mar-17 10:29 
GeneralRe: JQuery Not Found Pin
Sander Rossel2-Mar-17 10:32
professionalSander Rossel2-Mar-17 10:32 
AnswerRe: JQuery Not Found Pin
ZurdoDev2-Mar-17 10:16
professionalZurdoDev2-Mar-17 10:16 
GeneralRe: JQuery Not Found Pin
Kevin Marois2-Mar-17 10:16
professionalKevin Marois2-Mar-17 10:16 
GeneralRe: JQuery Not Found Pin
ZurdoDev2-Mar-17 10:18
professionalZurdoDev2-Mar-17 10:18 
GeneralRe: JQuery Not Found Pin
Kevin Marois2-Mar-17 10:28
professionalKevin Marois2-Mar-17 10:28 

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.