コード例 #1
0
        public DataTable BuscarFechaCita(DCita cita)
        {
            string        sql   = "sp_buscar_fechadetalle_cita";
            DataTable     tabla = new DataTable();
            SqlConnection cn    = new SqlConnection();

            try
            {
                cn.ConnectionString = Conexion.conectar;
                cn.Open();
                using (var da = new SqlDataAdapter(sql, cn))
                {
                    da.SelectCommand.Parameters.AddWithValue("@buscar", cita.FechaCita);
                    da.SelectCommand.CommandType = CommandType.StoredProcedure;
                    da.Fill(tabla);
                }
            }
            catch (Exception ex)
            {
                tabla = null;
                ex.Message.ToString();
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(tabla);
        }
コード例 #2
0
        public int InsertarCita(DCita cita)
        {
            int           ultimoId = 0;
            string        sql      = "sp_insertar_cita";
            SqlConnection cn       = new SqlConnection();

            try
            {
                cn.ConnectionString = Conexion.conectar;
                cn.Open();

                using (SqlCommand cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddWithValue("@idpagoservicio", cita.IdPagoServicio);
                    cmd.Parameters.AddWithValue("@idusuario", cita.IdUsuario);
                    cmd.Parameters.AddWithValue("@total", cita.Total);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@ultimoid", SqlDbType.Int).Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();
                    cn.Close();
                    ultimoId = Convert.ToInt32(cmd.Parameters["@ultimoid"].Value.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error ... ???", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(ultimoId);

                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(ultimoId);
        }