Buenas:
Estoy haciendo una aplicacion interna en c# .Net, mas que nada es una planilla web que permite agendar datos a un usuario x, bueno solamente inserta datos y consulta pero hoy me pidieron poder modificar uno de estos datos.
Adjunto accion del boton "grabar Datos"
com.CommandText = "ingresa_planilla"
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.Add("@id_usuario", SqlDbType.BigInt).Value = Convert.ToInt32(Session["id_usuario"].ToString());
com.Parameters.Add("@fecha", SqlDbType.NVarChar, 20).Value = TextBox1.Text;
com.Parameters.Add("@mes", SqlDbType.NVarChar, 20).Value = Convert.ToInt32(TextBox3.Text);
com.Parameters.Add("@hora", SqlDbType.NVarChar, 20).Value = DropDownList1.SelectedItem.ToString();
com.Parameters.Add("@cliente", SqlDbType.NVarChar, 20).Value = DropDownList2.SelectedItem.ToString();
com.Parameters.Add("@ubicacion", SqlDbType.NVarChar, 20).Value = DropDownList3.SelectedItem.ToString();
com.Parameters.Add("@reunion", SqlDbType.NVarChar, 20).Value = DropDownList4.SelectedItem.ToString();
com.Parameters.Add("@tareas", SqlDbType.NVarChar, 20).Value = DropDownList5.SelectedItem.ToString();
com.Parameters.Add("@observacion", SqlDbType.NVarChar, 255).Value = TextBox2.Text;
con.Open();
Procedimiento almacenado
ALTER procedure [dbo].[ingresa_planilla]
@id_usuario int,
@fecha nvarchar(20),
@mes int,
@hora nvarchar(10),
@cliente nvarchar(20),
@ubicacion nvarchar(20),
@reunion nvarchar(20),
@tareas nvarchar(20),
@observacion nvarchar(255)
as
begin
insert into planilla(usuario_id,fecha_registro,mes_corresponde,hora_registro,cliente,ubicacion,reunion,tareas,observacion) values(@id_usuario,@fecha,@mes,@hora,@cliente,@ubicacion,@reunion,@tareas,@observacion)
end
cada vez que se ejecuta el procedimiento "ingresa_planilla" este se guarda en una tabla que tiene un campo mas que es planilla_id este campo es autoincrementado en 1, su proposito es guardar un identificador por cada planilla que se genere.(en fin funciona todo correctamente)
Los problemas aparecen al realizar el procedimiento para modificar ya que la variable planilla_id no se como trabajarla para poder modificar los datos ej:
com.CommandText = "modifica_planilla";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.Add("@planilla_id", SqlDbType.BigInt).Value = ? ?Duda ? ?
com.Parameters.Add("@id_usuario", SqlDbType.BigInt).Value = Convert.ToInt32(Session["id_usuario"].ToString());
com.Parameters.Add("@fecha", SqlDbType.NVarChar, 20).Value = TextBox1.Text;
com.Parameters.Add("@mes", SqlDbType.NVarChar, 20).Value = Convert.ToInt32(TextBox3.Text);
com.Parameters.Add("@hora", SqlDbType.NVarChar, 20).Value = DropDownList1.SelectedItem.ToString();
com.Parameters.Add("@cliente", SqlDbType.NVarChar, 20).Value = DropDownList2.SelectedItem.ToString();
com.Parameters.Add("@ubicacion", SqlDbType.NVarChar, 20).Value = DropDownList3.SelectedItem.ToString();
com.Parameters.Add("@reunion", SqlDbType.NVarChar, 20).Value = DropDownList4.SelectedItem.ToString();
com.Parameters.Add("@tareas", SqlDbType.NVarChar, 20).Value = DropDownList5.SelectedItem.ToString();
com.Parameters.Add("@observacion", SqlDbType.NVarChar, 255).Value = TextBox2.Text;
Procedure modifica_planilla
ALTER procedure [dbo].[modifica_planilla]
@planilla_id BIGINT,
@id_usuario int,
@fecha nvarchar(20),
@mes int,
@hora nvarchar(10),
@cliente nvarchar(20),
@ubicacion nvarchar(20),
@reunion nvarchar(20),
@tareas nvarchar(20),
@observacion nvarchar(255)
as
begin
update planilla
set
fecha_registro = @fecha,
mes_corresponde = @mes,
hora_registro = @hora,
cliente = @cliente,
ubicacion = @ubicacion,
reunion = @reunion,
tareas = @tareas,
observacion = @observacion
WHERE planilla_id = @planilla_id
END
Mi consulta es como mando la variable planilla_id al procedimiento y como la declaro en :
com.Parameters.Add("@planilla_id", SqlDbType.BigInt).Value = ? ?Duda ? ?
Cualquier duda sera bien recibida
Gracias
realmente no entiendo tu duda, lo haces de la misma manera que con IdUsuario con el Convert.ToInt32, si te refieres a de donde obtener el idplanilla debes fijarte en donde estas dando click a modificar... explicanos en donde o a que esta asociado el boton de modificar para orientarnos...
Atentamente,
Juan Manuel Lombana
Medellín - Colombia
Dentro del boton modificar pretendo agregar el codigo que especifique arriba eJ:
com.CommandText = "modifica_planilla";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.Add("@planilla_id", SqlDbType.BigInt).Value = ? ?Duda ? ?
com.Parameters.Add("@id_usuario", SqlDbType.BigInt).Value = Convert.ToInt32(Session["id_usuario"].ToString());
com.Parameters.Add("@fecha", SqlDbType.NVarChar, 20).Value = TextBox1.Text;
com.Parameters.Add("@mes", SqlDbType.NVarChar, 20).Value = Convert.ToInt32(TextBox3.Text);
com.Parameters.Add("@hora", SqlDbType.NVarChar, 20).Value = DropDownList1.SelectedItem.ToString();
com.Parameters.Add("@cliente", SqlDbType.NVarChar, 20).Value = DropDownList2.SelectedItem.ToString();
com.Parameters.Add("@ubicacion", SqlDbType.NVarChar, 20).Value = DropDownList3.SelectedItem.ToString();
com.Parameters.Add("@reunion", SqlDbType.NVarChar, 20).Value = DropDownList4.SelectedItem.ToString();
com.Parameters.Add("@tareas", SqlDbType.NVarChar, 20).Value = DropDownList5.SelectedItem.ToString();
com.Parameters.Add("@observacion", SqlDbType.NVarChar, 255).Value = TextBox2.Text;
el problema aparece cuando tengo que enviar la variable al procedimiento
ya que las enviamos con esta sentencia:
com.Parameters.Add("@planilla_id", SqlDbType.BigInt).Value = ? ?Duda ? ?
el problema es que esta variable no la tengo en ningun TextBox ni DropDownList, solo esta en la base de datos, tonces no se como trabajarla para poder enviarla al procedimiento. ya que todas las variables que estoy mandando estan asignadas a algun textbox o cosas asi, pero esa variable no.
tu me decias que la trabajara igual como la id_usuario pero al momento de escribir:
com.Parameters.Add("@planilla_id", SqlDbType.BigInt).Value = Convert.ToInt32();
me arroja error, Visual me indica
Error 10 Ninguna sobrecarga para el método 'ToInt32' acepta '0' argumentos
Me entiendes estimado???
Crea una funcion que te retorne el valor que tienes en la BD y luego solo la invocas..
Problema solucionado, se agradecen las respuestas