in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

parameterized queries With Jocker

Last post 02-16-2010 11:04 AM by mijaelstand. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-14-2010 9:44 PM

    parameterized queries With Jocker

     hello guys. i want to talk you about a problem that i got it..

    i dont know how i could to write some parameterized query with a joker like "%".

    maybe im doing it in the right way cuze usually i do it in another database environments but i dont know what is the reason for it is not working...

    VS says me in the output file that sqlite doesnt  admit the % character.

    usually i only add the % character beside to parameter.

    im adding the jocker in this way :





     public DataTable ListarMedic_X_IdMedico(String P_IDMedic)
           {
               Consulta = "select medicos.Id_Medico as 'Codigo Del Medico' , medicos.nombre as 'Nombre Del Medico', medicos.telefono as 'Telefono', medicos.direccion as 'Direccion' , medicos.especialidad as 'Especialidad', medicos.turnos as 'Turnos Por Dia' from medicos where medicos.Id_Medico =@IdMedico%";

               Comando.Connection = Conexion;
               Comando.CommandText = Consulta;
               DataAda.SelectCommand = Comando;

               Comando.Parameters.Add("@IdMedico", DbType.String).Value = P_IDMedic;

               try
               {
                   Conexion.Open();
                   DataAda.Fill(Ds);
                   Conexion.Close();

               }

               catch (Exception e)
               {
                   System.Diagnostics.Debug.Print("Se ha presentado un error. " + Environment.NewLine.ToString() + Convert.ToString(e));
                   Conexion.Close();
                   return null;

               }

               return Ds.Tables[0];

           }


    aslo i tried in this way, but aslo it's not works :


               Consulta = "select medicos.Id_Medico as 'Codigo Del Medico' , medicos.nombre as 'Nombre Del Medico', medicos.telefono as 'Telefono', medicos.direccion as 'Direccion' , medicos.especialidad as 'Especialidad', medicos.turnos as 'Turnos Por Dia' from medicos where medicos.Id_Medico =@IdMedico" + "%";

     

    i hope that somebody can help me for to resolve this issuse.

    Regards

     

    Senior Software Developer:
    C# And VB Strong Programming.
  • 02-16-2010 3:33 AM In reply to

    • Knch
    • Top 50 Contributor
    • Joined on 02-10-2009
    • Posts 30

    Re: parameterized queries With Jocker

    Answer

    You'll need to use string concatenation for that.

    SELECT medicos.Id_Medico AS "Codigo Del Medico" , medicos.nombre AS "Nombre Del Medico", medicos.telefono AS "Telefono", medicos.direccion AS "Direccion" , medicos.especialidad AS "Especialidad", medicos.turnos AS "Turnos Por Dia" FROM medicos WHERE medicos.Id_Medico = @IdMedico || '%'

    String concatenation in SQLite is done with ||, not with +.

    Also, ' is used to delimit strings, so you can't use that to delimit field names (as you did in your original query.) To delimit fields you should use " (or enclose them between [ and ])

  • 02-16-2010 11:04 AM In reply to

    Re: parameterized queries With Jocker

    Answer
    Thanx you, i Resolved it in this way :

    Consulta = "select medicos.Id_Medico as 'Codigo Del Medico' , medicos.nombre as 'Nombre Del Medico', medicos.telefono as 'Telefono', medicos.direccion as 'Direccion' , medicos.especialidad as 'Especialidad', medicos.turnos 'Turnos Por Dia' from medicos where medicos.nombre like '%' || @mednombre || '%'";

    Aslo i put the aliases for my fields between " ", cuze VS doesnt admit with '. however it's working right now.

     

    Senior Software Developer:
    C# And VB Strong Programming.
Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems