Ver Mensaje Individual
  #6 (permalink)  
Antiguo 31/10/2012, 14:28
Avatar de DeivisAndres
DeivisAndres
 
Fecha de Ingreso: febrero-2012
Ubicación: Colombia
Mensajes: 305
Antigüedad: 12 años, 3 meses
Puntos: 41
Respuesta: Validar datos de que ingrese un usuario sean iguales al de la Base de Dato

Sencillo pondré solo unos campos nada mas. Digamos que solo tenemos los campos: código_formulario, identificación_usuario, código, tipo_formulario(Peticiones, Quejas y Reclamos), comentario.

Digamos que el ya registro unos datos y son:

1, 1143359834, MD0215, Peticiones, No me gusto nada.

En la consulta yo haría lo siguiente:

Código Javascript:
Ver original
  1. string identificacion_usuario = this.txtUsuario.Text;
  2. string codigo = this.txtcodigo.Text;            
  3.  
  4.            
  5. SqlConnection Conection = new SqlConnection(CadenaString);
  6.  
  7. Conection.Open();
  8.  
  9.  
  10. SqlCommand ComandoSql = new SqlCommand("SELECT * FROM table_formulario WHERE  identificación_usuario = @Username AND codigo = @codigo", Conection);
  11. ComandoSql.Parameters.AddWithValue("@Username", identificacion_usuario.Replace("'", "NOoo"));
  12. ComandoSql.Parameters.AddWithValue("@codigo", codigo.Replace("'", "NoOo"));
  13.            
  14. SqlDataReader Leer = ComandoSql.ExecuteReader();
  15.  
  16. if (Leer.Read())
  17. {                
  18.  this.textpersona.Text = Leer["identificación_usuario"];
  19.  this.textcodigo.Text = Leer["codigo"];                  
  20.  this.texttipo.Text = Leer["tipo_formulario"];
  21.  this.textcomentario.Text = Leer["comentario"];              
  22. }
  23. else
  24. {
  25.  ............................
  26. }
  27.  
  28. Leer.Close();
  29. Conection.Close();


Ó de otra manera seria de esta forma:

Código Javascript:
Ver original
  1. SqlConnection Conection = new SqlConnection(CadenaString);
  2. Conection.Open();
  3.            
  4. String CadenaSQL = "SELECT * FROM table_formulario WHERE  identificación_usuario = " + identificacion_usuario + " AND codigo = " + codigo + "";
  5.  
  6.  
  7. sqlDataAdapter Adapatador = new SqlDataAdapter(CadenaSQL, Conection);
  8.  
  9.  
  10. DataSet DS = new DataSet();
  11. Adapatador.Fill(DS); // Llenamos el DS, el objeto el cual nos sirve para poder manipular los datos.
  12.  
  13.            
  14. if (DS.Tables[0].Rows.Count == 0)
  15. {
  16.     DS.Dispose();
  17.         this.label.Text = "Usted no a realizado ninguna pregunta";
  18. }
  19. else
  20. {
  21.  this.textpersona.Text = DS.Tables[0].Rows[0]["identificación_usuario"].ToString();
  22.  this.textcodigo.Text = DS.Tables[0].Rows[0]["codigo"].ToString();
  23.  this.texttipo.Text = DS.Tables[0].Rows[0]["tipo_formulario"].ToString();
  24.  this.textcomentario.Text = DS.Tables[0].Rows[0]["comentario"].ToString();
  25.  
  26.  DS.Dispose();
  27.                
  28. }
  29. Conection.Close();


Espero y me hayas entendido.