Ver Mensaje Individual
  #6 (permalink)  
Antiguo 23/06/2011, 15:33
Avatar de ldcd
ldcd
 
Fecha de Ingreso: enero-2010
Ubicación: Distrito Federal
Mensajes: 57
Antigüedad: 14 años, 3 meses
Puntos: 6
Respuesta: sumar valor con valor existente en campo

Código:
public void ExecuteSql(int id)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand())
{
connection.Open();

command.Connection = connection;
command.CommandType = System.Data.CommandType.Text;
string sql = string.Format("SELECT cantidad_producto, nueva_cantidad FROM Productos WHERE Id = {0}", id);
command.CommandText = sql;
command.CommandTimeout = 10;

SqlDataReader reader = command.ExecuteReader();
int cantidadProd = reader.GetInt32(0).value;
int nuevaCantidad = reader.GetInt32(1).value;
textBox1.Text = cantidadProd + nuevaCantidad;
}
}
}
Ya solo le tienes que pasar el Id para realizar la consulta por registro