trevor1940
asked on
C# How to populate a listbox from an SQL query
Hi
I'm new to C#
I'm trying to populate a listbox from an database query the idea is to be able to click a movie title and then fetch other info about that movie using the movie id
I've connected to the SQLite database (See Pic) and added a listbox named TitleListbox to my MainWindow.xaml
Now I'm stuck
How do I populate the TitleListbox?
I'm new to C#
I'm trying to populate a listbox from an database query the idea is to be able to click a movie title and then fetch other info about that movie using the movie id
I've connected to the SQLite database (See Pic) and added a listbox named TitleListbox to my MainWindow.xaml
Now I'm stuck
How do I populate the TitleListbox?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetTitles();
}
private void GetTitles(ListBox TitleListBox)
{
TitleListBox.Items.Clear();
MovieDatabaseDataSet ds = new MovieDatabaseDataSet("select id,title,tmdbId from movie order by title");
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can some one show me the code how to do this?
I don't understand how to implement the last Experts comments
I don't understand how to implement the last Experts comments
You have to populate the data set from the XSD. I thought you already had that portion done.
You have to do 2 things:
1) Create the structure from the dataset:
from: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/loading-dataset-schema-information-from-xml
and
2: Populate the dataset:
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/loading-a-dataset-from-xml
from there you can run the select on the table as shown.
You have to do 2 things:
1) Create the structure from the dataset:
from: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/loading-dataset-schema-information-from-xml
DataSet dataSet = new DataSet();
dataSet.ReadXmlSchema("schema.xsd");
and
2: Populate the dataset:
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/loading-a-dataset-from-xml
string xmlData = "<XmlDS><table1><col1>Value1</col1></table1><table1><col1>Value2</col1></table1></XmlDS>"; // change to your real data, can read from a file or whatever.
System.IO.StringReader xmlSR = new System.IO.StringReader(xmlData);
dataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);
from there you can run the select on the table as shown.
ASKER
Now you've totally lost me
The data comes from an SQL query why do I need to create an XML file?
All I'm trying to do is populate a list box with film titles (this Works)
When user Clicks a title I want to get the film ID not the selected index
The data comes from an SQL query why do I need to create an XML file?
All I'm trying to do is populate a list box with film titles (this Works)
When user Clicks a title I want to get the film ID not the selected index
ASKER
I'm closing this unresolved
ASKER
it say MovieDatabaseDataSet dose not contain a constructor that takes 1 argument
Open in new window