I have a C# program that uses SQLite in a UWP application. I have 2 classes, my main class and my sql container class.
My sql container class (SQLManage) has the following code:
private void totalWorthBtn_Click(object sender, RoutedEventArgs e)
{
// SELECT sum(Artwork.worth) as totalGalleryWorth, Gallery.galleryName from Gallery INNER JOIN Artwork on Gallery.GalleryID = Artwork.galleryiD where Gallery.galleryName = 'CatLand';"
dataManager.ArtworkAvgQuery("SELECT round(avg(Artwork.worth),2) as avgArtworkWorth, Gallery.galleryName from Gallery INNER JOIN Artwork on Gallery.GalleryID = " +
"Artwork.galleryiD where Gallery.galleryName = '\"" + $"{Input.Text}" + "\"'; ");
while (dataManager.queryResult.Read())
{
if (firstPass == true) { counter++; }
Debug.WriteLine(dataManager.queryResult.GetDouble(0));
Debug.WriteLine(dataManager.queryResult.GetString(1));
}
firstPass = false;
dataManager.database.Clos
This is the method where I try and use Input.Text (a textbox) to be used for a where clause.
My schema has the following inserts into 3 tables
public void CreateArtists()
{
dataManager.InsertIntoArtist(1, "Jimmy", "2003-07-11", "Alive");
dataManager.InsertIntoArtist(2, "Johnny", "1998-03-11", "Alive");
dataManager.InsertIntoArtist(3, "Bonny", "2007-05-12", "Alive");
dataManager.InsertIntoArtist(4, "Jesus", "0000-12-25", "InCatHeaven");
}
public void CreateGalleries()
{
dataManager.InsertIntoGallery(1, "FunLand", "37 DateLand St");
dataManager.InsertIntoGallery(2, "MiseryLand", "38 DateLand St");
dataManager.InsertIntoGallery(3, "DisneyLand", "39 DateLand St");
dataManager.InsertIntoGallery(4, "CatLand", "40 DateLand St");
}
public void CreateArtwork()
{
dataManager.InsertIntoArtwork(1, 4, 4, "Statue", 30, 30, 5, 15000);
dataManager.InsertIntoArtwork(2, 4, 4, "Painting", 5, 15, 2, 75500);
dataManager.InsertIntoArtwork(3, 2, 2, "Painting", 15, 15, 2, 175670);
}
I am trying to have the database with userInput for the where of some of these queries, I was trying to have the user be able to enter into a textbox lets say 'catland' and the SQL would find that table and result in it, instead of manually being done with literal values.
I am just not sure if this can be done, or if this is a good way of going around it. I'm quite new to SQL and am trying to get a better understanding of how this works. I would appreciate if you guys could help me go in the right direction.
In terms of the error I am getting when I click the total worth button when Input.Text is there I get the following Error:
System.InvalidOperationException: 'The data is NULL at ordinal 0. This method can't be called on NULL values. Check using IsDBNull before calling.'
I am not too sure how to fix this, can you please help me <3