I want to show all books from selected writers from checkedlistbox on chart. Problem is that I need to merge two columns and it throws exception on line da.Fill(dt1): Invalid column name ime_prezime
conn.Open();
//chart1.Series.Clear();
//string predmeti = "";
string result = "";
string[] sAutori;
foreach (object itemChecked in checkedListBox1.CheckedItems)
{
DataRowView castedItem = itemChecked as DataRowView;
string companyName = (string)castedItem["ime_prezime"];
//int? id = castedItem["autor_id"];
result += $@"'({companyName})'" + ",";
}
if (checkedListBox1.CheckedItems.Count < 2)
{
MessageBox.Show("Morate izabrati bar dva pisca!");
}
else
{
result = result.Substring(0, result.Length - 1);
//string result = predmeti.Substring(0, predmeti.Length - 1);
cmd1.CommandText = $@"SELECT a.ime + ' ' + a.prezime AS ime_prezime, COUNT(b.knjiga_id) FROM AUTORI AS a JOIN autori_izdanja AS b ON a.autor_id = b.autor_id WHERE ime_prezime IN ({result}) GROUP BY a.ime";
da.SelectCommand = cmd1;
da.Fill(dt1);
try {
foreach (DataRow row in dt1.Rows)
{
chart1.Series[0].Points.AddXY(row[0], row[1]);
}
label2.Text = result;
button1.Enabled = false;
}
catch (Exception g) {
MessageBox.Show(g.Message);
}
}
conn.Close();
Can someone solve this please...