Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/06/2011, 05:25
Avatar de ir3al
ir3al
 
Fecha de Ingreso: mayo-2010
Ubicación: Talavera de la Reina
Mensajes: 110
Antigüedad: 14 años
Puntos: 4
Meter datos de un DataRow en unos textbox's

Buenas, no me deja poner unos valores obtenidos de un DataRow en unos textboxs como el texto de esos textbox. me da este error, os pongo una imagen:


Os dejo aqui el codigo tambien:
Código c#:
Ver original
  1. private void buscar_codigo(object sender, EventArgs e)
  2.         {
  3.             //bool val = false;
  4.             if (vali.validarCod(textBox1.Text))
  5.             {
  6.                 PUB2.DB2.ClearPar();
  7.                 PUB2.DB2.AddParam("CODIGO", textBox1.Text);
  8.  
  9.                 DataTable dat = PUB2.DB2.DevuevleDataTable("SELECT COD_CLI, NOMBRE, NUMCOPIAS, EMAIL, TLF_1 FROM CLIENTES WHERE COD_CLI = ?CODIGO");
  10.  
  11.                 if(dat.Rows.Count > 0){
  12.                    
  13.                     foreach(DataRow col in dat.Rows){
  14.  
  15.                         string cod = col["COD_CLI"].ToString();
  16.                         string nom = col["NOMBRE"].ToString();
  17.                         string cop = col["NUMCOPIAS"].ToString();
  18.                         string email = col["EMAIL"].ToString();
  19.                         string telf = col["TLF_1"].ToString();
  20.  
  21.                         //MessageBox.Show("variable" + nom);
  22.  
  23.                         Buscar_Alta.alt.textCod.Text = cod;
  24.                         Buscar_Alta.alt.textNom.Text = nom;
  25.                         Buscar_Alta.alt.textTelf.Text = telf;
  26.                         Buscar_Alta.alt.textEmail.Text = email;
  27.                         Buscar_Alta.alt.textCop.Text = cop;
  28.  
  29.                     }//FIN foreach
  30.  
  31.                     Buscar_Alta.alt.ShowDialog();
  32.                     this.Close();
  33.  
  34.                 }//fin if
  35.                 else{
  36.                     MessageBox.Show("No existe ningún cliente con ese código.", "No existe ese usuario.", MessageBoxButtons.OK, MessageBoxIcon.Error);
  37.                     textBox1.Clear();
  38.                     textBox1.Focus();
  39.                 }//fin else
  40.             }//FIN if
  41.             else
  42.             {
  43.                 MessageBox.Show("El código que ha introducido es incorrecto, debe tener una longitud de 8 caracteres, solamente puede contener digitos y letras.", "Error codigo introducido.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  44.                 textBox1.Clear();
  45.                 textBox1.Focus();
  46.             }//FIN else
  47.         }//FIN buscar_codigo

Necesito ayuda rapida por favor.
Un saludo.