Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/10/2011, 10:44
mrprogman
 
Fecha de Ingreso: junio-2011
Mensajes: 329
Antigüedad: 13 años, 8 meses
Puntos: 2
Update e Insert juntos en 1 boton

saludos a todos..tengo una duda. tengo 2 botones..uno para actualizar una bd y otro para generar un numero en una tabla , ambos afectan a tablas diferentes, se podra juntar a ambos en un solo boton..este es mi codigo..

boton 1
-------------------------------------------
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim cadtexto As String
Dim rg 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()

For i As Integer = 0 To contactsListBox.Items.Count - 1
'Aqui ya hacer la insercion en tu tabla
cadtexto = "update ocfiltro Set Agencia = ' " + DropDownList1.Text + " ' ,Paquete = ' " + TextBox1.Text + " ' where oc= '" & contactsListBox.Items(i).ToString & "' "
myCommand = New SqlCommand(cadtexto, myConnection)
rg = myCommand.ExecuteNonQuery()
'myConnection.Close()

Next i
'myCommand = New SqlCommand(cadtexto, myConnection)
'rg = myCommand.ExecuteNonQuery()
myConnection.Close()
Server.Transfer("Pruebas4.aspx")

boton 2
--------------------------------------------

Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim cadtexto As String
Dim rg 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 = "Insert into Paquetesdos (numpaq) values ('" & TextBox2.Text & "')"
'sSQL = "Insert into tClientes (Nombre, Apellido, Pais, Ciudad) values ('" & Nombre.text & "', '" & Apellido.text & "', '" & Pais.text & "', '" & Ciudad.text & "')"

myCommand = New SqlCommand(cadtexto, myConnection)
rg = myCommand.ExecuteNonQuery()

'Label6.Text = rg
myConnection.Close()
Server.Transfer("Pruebas4.aspx")