pass string parameter from textbox in one window to another windiw in C#
Posted on 2010-03-25
Here is my question:
This is in a WPF application using C#
I have a textbox that looks like this:
<TextBox Height="23" Name="textBox1" Width="88" />
My code takes the string that was input in the textbox and puts it in a SQL server query and when a user presses a submit button it queries the database.
So in my code file: Window1.xaml.cs this is the code that handled the textbox string
private string GenerateQuery()
string val = null;
string recordNumber = textBox1.Text;
val = "SELECT RECORD_NUMBER, PAGES, RECORD_DATE FROM TABLE1 WHERE RECORD_NUMBER = '" + recordNumber + "'";
That works fine and dandy.
So on another page called Window2.xaml
In part of the C# code
I have a query that looks like this
query += "FROM TABLE1 WHERE RECORD_NUMBER = '" + recordNumber + "'";
Is there a way that I can access the string variable recordNumber that was input into textbox1 in Window1 from my code in Window2?
I thought maybe i can declare the variable again in window2.xaml.cs and do it like this:
Saying "I am declaring a variable called recordNumber which is found in Window1"
string recordNumber = Window1.textBox1.Text;
But it's not liking that. Has anyone done this before? Can anyone help?