In my SqlDataSource I've defined the Select, Insert, Update y Delete Command. The SelectCommand is a query from a function which returns a table, it receives a parameters which I write directly in the SelectCommand, at this point all is right, the grid shows
the records and I can insert a new line, modify it or delete it, everything is fine.
But when I replace the SelectCommand at runtime, for adding dynamic parameters and a where clause, all the actions don't work!
Finally, I assign the GetProducts function as DataSource of the grid
EDIT: I resolved it, for them who want to know, in the SqlDataSource I defined the commands to Insert/Update/Delete, then, I replaced the SqlDataSource by the function, so I lost all my commands, what I did was modify the SelectCommand property.
EDIT: I resolved it, for them who want to know, in the SqlDataSource I defined the commands to Insert/Update/Delete, then, I replaced the SqlDataSource by the function, so I lost all my commands, what I did was modify the SelectCommand property.
Hi,
I come here and check that your problem is solved. I'll close the issue by marking yours an answer and welcome your futher feedback by creating another new issue here.
jos3
Member
7 Points
43 Posts
Error Adding/Editing/Deleting when SelectCommand builded at runtime
Nov 13, 2012 08:52 AM|LINK
Hi,
In my SqlDataSource I've defined the Select, Insert, Update y Delete Command. The SelectCommand is a query from a function which returns a table, it receives a parameters which I write directly in the SelectCommand, at this point all is right, the grid shows the records and I can insert a new line, modify it or delete it, everything is fine.
But when I replace the SelectCommand at runtime, for adding dynamic parameters and a where clause, all the actions don't work!
This is my code, what is wrong with it?
public static SqlCommand CrearComando() { string conexion = @"Data Source=; Initial Catalog=; User=; Password="; SqlConnection objConexion = new SqlConnection(); objConexion.ConnectionString = conexion; SqlCommand objComando = new SqlCommand(); objComando = objConexion.CreateCommand(); objComando.CommandType = CommandType.Text; return objComando; } public static DataTable EjecutarComandoSelect(SqlCommand comando) { DataTable tabla = new DataTable(); try { comando.Connection.Open(); SqlDataAdapter objAdaptador = new SqlDataAdapter(); objAdaptador.SelectCommand = comando; objAdaptador.Fill(tabla); } catch (Exception ex) { throw ex; } finally { comando.Connection.Close(); } return tabla; } public static DataTable GetProducts(string parametros) { string[] param = parametros.Split(';'); SqlCommand objComando = CrearComando(); objComando.CommandText = "SELECT Product, Name, Category, Section " + "FROM fn_Products(" + param[0] + ", " + param[1] + ", " + param[2] + ") " + "WHERE Category=" + param[3] + " AND Section ='" + param[4] + "'"; return EjecutarComandoSelect(objComando); }Finally, I assign the GetProducts function as DataSource of the grid
EDIT: I resolved it, for them who want to know, in the SqlDataSource I defined the commands to Insert/Update/Delete, then, I replaced the SqlDataSource by the function, so I lost all my commands, what I did was modify the SelectCommand property.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Error Adding/Editing/Deleting when SelectCommand builded at runtime
Nov 14, 2012 12:42 AM|LINK
Hi,
I come here and check that your problem is solved. I'll close the issue by marking yours an answer and welcome your futher feedback by creating another new issue here.
Reguards!