enter image description here

adapter = new SqlDataAdapter("SELECT tRoutesPuncts.ID_Punct, tPuncts.sPunct FROM dbo.tRoutesPuncts INNER JOIN tRoutes ON dbo.tRoutesPuncts.ID_Route = dbo.tRoutes.ID_Route" + " inner join tPuncts ON dbo.tRoutesPuncts.ID_Punct = dbo.tPuncts.ID_Punct WHERE tRoutesPuncts.ID_Route=" + id.Text, connection); dtForAddPuncts = new DataTable(); adapter.Fill(dtForAddPuncts); bsForAddPuncts= new BindingSource(); bsForAddPuncts.DataSource = dtForAddPuncts; cbAddPuncts.DataSource = bsForAddPuncts; cbAddPuncts.ValueMember = "ID_Punct"; cbAddPuncts.DisplayMember = "sPunct"; } 

The error appears here: "adapter.Fill (dtForAddPuncts);"

enter image description here enter image description here

  • Do you have any comment on exactly where you have the problem. Apparently in the assignment of the adapter? - StriBog
  • It is not necessary so - directly in the request some fields from user input - a security hole. Well, and probably still need to take quotes) - Sergey
  • an error occurs here "adapter.Fill (dtForAddPuncts);" - Tema4910
  • Tried to take in quotes, does not help: (More precisely, the error disappears, but in the comboBox does not display anything. And if you replace the text of the comboBox in the sql query and put a certain value, then everything works perfectly. - Tema4910
  • adapter = new SqlDataAdapter ($ "SELECT tRoutesPuncts.ID_Punct, tPuncts.sqthafees FR un t FR FR FR FR FR FR FR FR t P P t P t t t P P P P P P t P t P t t t t t t t t t t P P P P t t P t t t t t t t t P P t t s. P t t t P .ID_Punct WHERE tRoutesPuncts.ID_Route = [{id.Text}] ", connection); and there is a new convenient line formatting with a dollar sign - Sasuke

2 answers 2

It stores the value of the current ID_Route at the tRoutes table.

What do you mean, Stanislavsky?

Write already what is there for the text, otherwise I will put a minus to you.


<дистанционноС Ρ‡Ρ‚Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ΄Π° сквозь ΠΌΠΎΠ½ΠΈΡ‚ΠΎΡ€>

The string id.Text is empty. Accordingly, SQL ends with

 ... WHERE tRoutesPuncts.ID_Route= 

which is syntactically wrong.

Let's get, instead of your mistake, we get a conversion error:

 int ID_Route = int.Parse(id.Text); adapter = new SqlDataAdapter("SELECT tRoutesPuncts.ID_Punct, tPuncts.sPunct FROM dbo.tRoutesPuncts INNER JOIN tRoutes ON dbo.tRoutesPuncts.ID_Route = dbo.tRoutes.ID_Route" + " inner join tPuncts ON dbo.tRoutesPuncts.ID_Punct = dbo.tPuncts.ID_Punct WHERE tRoutesPuncts.ID_Route=" + ID_Route.ToString(), connection); 

</дистанционноС Ρ‡Ρ‚Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ΄Π° сквозь ΠΌΠΎΠ½ΠΈΡ‚ΠΎΡ€>

  • Sorry for not describing everything in such detail, I’m attaching the screenshots now :) - Tema4910
  • everything, in question threw the necessary screenshots :) - Tema4910
  • one
    @ Tema4910 I bet this is not the TextBox you are thinking about? Stop in the debugger on the line dtForAddPuncts = new DataTable(); and see which SQL is in the adapter. Tell us the result. - Igor
 void LoadDataFromRoutesPuncts(int id) { adapter = new SqlDataAdapter("SELECT tRoutesPuncts.ID_Punct, tPuncts.sPunct FROM dbo.tRoutesPuncts INNER JOIN tRoutes ON dbo.tRoutesPuncts.ID_Route = dbo.tRoutes.ID_Route" + " inner join tPuncts ON dbo.tRoutesPuncts.ID_Punct = dbo.tPuncts.ID_Punct WHERE tRoutesPuncts.ID_Route=" + id, connection); dtForAddPuncts = new DataTable(); adapter.Fill(dtForAddPuncts); bsForAddPuncts = new BindingSource(); bsForAddPuncts.DataSource = dtForAddPuncts; cbAddPuncts.DataSource = bsForAddPuncts; cbAddPuncts.ValueMember = "ID_Punct"; cbAddPuncts.DisplayMember = "sPunct"; } LoadDataFromRoutesPuncts(Convert.ToInt32(((DataRowView)this.bsForRoutes.Current).Row["ID_Route"]));