I'm getting this error when I'm trying to open a form in my C# App and I don't know what might be the problem. The error is in this line of code DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader());
Error:
{"Incorrect syntax near ','."}
public void popTraseu()
{
string cs = "Data Source=CODRINMA\\CODRINMA;Initial Catalog=TrafficManager;Integrated Security=True";
string select = "ats.NrOrdine, a.IDAutogara, a.Denumire as Autogara, o.Oras as Oras, o.Judet FROM Curse c INNER JOIN Trasee t on c.IDTraseu=t.IDTraseu INNER JOIN AutogariTrasee ats on t.IDTraseu=ats.IDTraseu INNER JOIN Autogari a on ats.IDAutogara=a.IDAutogara INNER JOIN Orase o on a.IDOras=o.IDOras where IDCursa=@IDCursa ORDER BY ats.NrOrdine";
try
{
using (SqlConnection con = new SqlConnection (cs))
{
con.Open();
SqlCommand cmd = new SqlCommand(select, con);
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("IDCursa", int.Parse(grdCurse.CurrentRow.Cells[0].FormattedValue.ToString()));
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
con.Close();
grdDetalii.DataSource = dt;
}
}
catch (Exception er) { MessageBox.Show(er.Message); }