private void FrmAgregarTipo_Load(object sender, EventArgs e) { AdminBD adminBD = new AdminBD(); adminBD.AbrirConexion(); string comando = string.Empty; comando = "SELECT Tipo FROM PersonaTipo WHERE "; for (int i = 0; i < tipoUsuarioExistentes.Length; i++) { if (i == 0) { comando += $"Tipo <> '{tipoUsuarioExistentes[i]}' "; } else { comando += $" AND Tipo <> '{tipoUsuarioExistentes[i]}'"; } } SqlDataReader dataReader = (SqlDataReader)adminBD.EjecutarComando(comando); DataTable dt = new DataTable(); if (dataReader != null) { dt.Load(dataReader); adminBD.CerrarConexion(); } CmbTipos.DataSource = dt; CmbTipos.DisplayMember = "Tipo"; CmbTipos.SelectedIndex = -1; }
private void ObtenerRegistro() { string comandoSql = "SELECT P.ID, PT.[Tipo], P.Saludo, P.Apellido, P.Telefono, P.Direccion1, P.Direccion2," + " P.Ciudad,P.Estado,P.[CodigoPostal] FROM Persona P" + $" INNER JOIN PersonaTipo PT ON PT.[PersonaID] = P.[ID] WHERE PT.Tipo = '{_tipo}'"; if (!string.IsNullOrEmpty(TxtBoxBuscar.Text)) { string filtro = TxtBoxBuscar.Text; comandoSql += $"AND (P.Nombre LIKE '{filtro}%' OR P.Apellido LIKE '{filtro}%'" + $" OR P.Email LIKE '{filtro}%' OR P.Email LIKE '{filtro}%' OR P.Ciudad LIKE '{filtro}%'" + $" OR P.Telefono LIKE '{filtro}%' OR P.CodigoPostal LIKE '{filtro}%'" + $" OR P.Direccion1 LIKE '{filtro}%' OR P.Direccion1 LIKE '{filtro}%')"; } AdminBD adminBD = new AdminBD(); adminBD.AbrirConexion(); SqlDataReader lector = (SqlDataReader)adminBD.EjecutarComando(comandoSql); if (lector != null) { DataTable tabla = new DataTable(); tabla.Load(lector); GrdPrincipal.DataSource = tabla; GrdPrincipal.Columns[0].Visible = false; lector.Close(); } adminBD.CerrarConexion(); }