In a MyViewModel I have a string property (SearchBox) that is binded to a textbox in my view. When I click the searchbutton A command get send to my datalayer class to get the searchresult (images) from the dB.
My problem is how to pass the string from the searchBox along with the method to use in the datalayer class.
public class MyViewModel : NotifyUIBase
{
private string _searchBox;
public string SearchBox // the Name property
{
get { return this._searchBox; }
set { this._searchBox = value; RaisePropertyChanged(); }
}
public MyViewModel()
{
FindImageCommand = new RelayCommand(FindImage);
}
public RelayCommand FindImageCommand { get; private set; }
private void FindImage()
{
var dbFunctions = new DatabaseFunctions();
FindVisualReferences = dbFunctions.FindVisualReferences();
}
}
In the DataLayer class I need to use the string from the SearchBox in the query to search the dB.
public class DataLayer
{
public ObservableCollection<Image> FindVisualReferences()
{
var FindVisualReferences = new ObservableCollection<Image>();
String dbConnectionString = @"Data Source =mydB.sqlite";
SQLiteConnection cnn = new SQLiteConnection(dbConnectionString);
cnn.Open();
====> string Query = "Select* from images where title = '" + SearchBox.ToUpper() + "'";
SQLiteDataAdapter sda = new SQLiteDataAdapter(Query, cnn);
DataTable dt = new DataTable();
sda.Fill(dt);
// rest of dB method
}
}
How do I get the string from SearchBox in MyViewModel into the query to search the database in the DataLayer Class?