Foros del Web » Programación para mayores de 30 ;) » .NET »

actualizar varios textbox al mismo tiempo

Estas en el tema de actualizar varios textbox al mismo tiempo en el foro de .NET en Foros del Web. alguien sabe como puedo actualizar varios texbox al mismo tiempo..tengo el sig codigo.. me gustaria evitar todo este codigo.. Dim cadtexto As String Dim cadtexto2 ...
  #1 (permalink)  
Antiguo 20/09/2011, 18:51
 
Fecha de Ingreso: junio-2011
Mensajes: 329
Antigüedad: 12 años, 10 meses
Puntos: 2
actualizar varios textbox al mismo tiempo

alguien sabe como puedo actualizar varios texbox al mismo tiempo..tengo el sig codigo..


me gustaria evitar todo este codigo..
Dim cadtexto As String
Dim cadtexto2 As String
Dim cadtexto3 As String
Dim cadtexto4 As String
Dim cadtexto5 As String
Dim rg As Integer
Dim rg1 As Integer
Dim rg2 As Integer
Dim rg3 As Integer
Dim rg4 As Integer
myConnection = New SqlConnection("Data Source=DELLMR;Initial Catalog=Compras;Persist Security Info=True;User ID=sa;Password=Stm01;Connect Timeout=200 ")

myConnection.Open()
cadtexto = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & TextBox3.Text.Trim & " ' "
cadtexto2 = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & TextBox4.Text.Trim & " ' "
cadtexto3 = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & TextBox5.Text.Trim & " ' "
cadtexto4 = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & TextBox6.Text.Trim & " ' "
cadtexto5 = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & TextBox7.Text.Trim & " ' "
myCommand = New SqlCommand(cadtexto, myConnection)
myCommand = New SqlCommand(cadtexto2, myConnection)
myCommand = New SqlCommand(cadtexto3, myConnection)
myCommand = New SqlCommand(cadtexto4, myConnection)
myCommand = New SqlCommand(cadtexto5, myConnection)
rg = myCommand.ExecuteNonQuery()
rg1 = myCommand.ExecuteNonQuery()
rg2 = myCommand.ExecuteNonQuery()
rg3 = myCommand.ExecuteNonQuery()
rg4 = myCommand.ExecuteNonQuery()

los campos q necesito actualizar son del texbox3 al textbox7...saludos y gracias
  #2 (permalink)  
Antiguo 21/09/2011, 08:42
 
Fecha de Ingreso: junio-2010
Mensajes: 49
Antigüedad: 13 años, 11 meses
Puntos: 2
Respuesta: actualizar varios textbox al mismo tiempo

Lo primero, mejor utilizar arrais que declarar tanta variable terminada en número, mas limpio todo.

Lo segundo, cada vez que haces "myCommand = New SqlCommand(cadtexto, myConnection)" estás haciendo un nuevo comando, con lo cual los que hiciste antes se descartan, solo te vale el último.

Prueba con esto:

myConnection = New SqlConnection("Data Source=DELLMR;Initial Catalog=Compras;Persist Security Info=True;User ID=sa;Password=Stm01;Connect Timeout=200 ")
myCommand = New SqlCommand
myCommand.Connection = myConnection
Dim txt(4) as string = {Trim(TextBox3.text), Trim(TextBox4.text), Trim(TextBox5.text), Trim(TextBox6.text), Trim(TextBox7.text)}
myConnection.Open()
for i = 0 to txt.GetUpperBound(0)
myCommand.CommandText = "Update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox2.Text + " ' where oc ='" & txt(i) & " ' "
myCommand.ExecuteNonQuery()
next
myConnection.Close()

Etiquetas: sql, textbox
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:58.